NAME
Twilio::Rest::Webhooks::V1::Rule - The Rule resource
SYNOPSIS
my $client = Twilio::Rest::Client->new($account_sid, $auth_token);
my $rule = $client->webhooks->v1->rules->create(\%body, \%options);
for my $rule ($client->webhooks->v1->rules->read({}, 20)) {
...
}
my $rule = $client->webhooks->v1->rules($rule_id)->fetch;
$client->webhooks->v1->rules($rule_id)->patch(\%body, \%options);
$client->webhooks->v1->rules($rule_id)->delete;
DESCRIPTION
This file holds RuleList, RulePage, RuleContext, RuleInstance and RuleOperationResponseInstance. Methods that make a request throw Twilio::Exceptions::RestException on an error response.
RuleList
Returned by $client->webhooks->v1->rules. See also Twilio::ListResource.
create
my $rule = $client->webhooks->v1->rules->create(\%body, \%options);
Creates a URL matching rule. Returns immediately after validation, then propagates globally. ### How It Works Immediate: Request validated → 202 Accepted (with Operation-Id header) or 4xx error Async (30-60s): Propagates globally. Poll /Operations/{id} for status (pending → completed) ### During Propagation During propagation, matching webhooks may use other rules (e.g., default) until this rule is active. ### Security Restrictions Default rules (matchType: default) cannot use Basic Authentication. Use OAuth2, Digest, or create specific URL patterns instead. Returns a RuleOperationResponseInstance.
%body is sent as JSON. It takes the names Twilio's API documentation uses.
The options are:
idempotency_key-
Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
read
my @records = $client->webhooks->v1->rules->read(\%options, $limit, $page_size);
Returns paginated list of Rules sorted by evaluation order: 1. exact-match rules (evaluated first, longest match first) 2. prefix-match rules (longest prefix first) 3. default rule (matches all incoming requests when no other rule matches). Returns the records as a list, fetching as many pages as it needs.
The options are:
setting_id-
Filter Rules that reference this Setting ID
stream
my $stream = $client->webhooks->v1->rules->stream(\%options, $limit, $page_size);
Takes the same arguments as "read", and returns a Twilio::Stream.
page
my $page = $client->webhooks->v1->rules->page(\%options, $page_size, $page_token);
Fetches one page, and returns a Twilio::TokenPaginationPage. This API pages by token, so there is no page number.
get_page
my $page = $client->webhooks->v1->rules->get_page($url);
Fetches the page at a URL given by Twilio.
get_context
my $context = $client->webhooks->v1->rules->get_context($rule_id);
Returns a RuleContext, and makes no request.
RulePage
A Twilio::Page of RuleInstance objects.
records_key
build_instance
Used by Twilio::Page.
RuleContext
Returned by $client->webhooks->v1->rules($rule_id). It makes no request until one of these methods is called.
fetch
my $rule = $client->webhooks->v1->rules($rule_id)->fetch;
Returns a Rule by its ID, including matchType, match value, and current traffic distribution settings. Returns a RuleInstance.
patch
my $rule = $client->webhooks->v1->rules($rule_id)->patch(\%body, \%options);
Updates rule configuration. Returns 202 Accepted, propagates in 30-60 seconds. ### Gradual Rollout Pattern Test configuration changes with production traffic before full deployment. Strategy: Gradually shift traffic to new Setting, monitor, increase to 100%. Flow: 90/10 → 50/50 → 0/100 (rollback to 100/0 if issues) ### During Propagation During propagation (~30-60s), webhooks may use previous or updated config until change is active. ### Use Cases - Credential rotation: Verify new auth works before full cutover - Timeout tuning: Test connection settings with real traffic ### What Can Change - friendlyName, description: Metadata - settings: Traffic distribution (percentages must sum to 100) - matchType + its companion value (prefix or value): changes the rule's match type and value together (async, same 30-60s propagation as any other patch). Returns 409 if the new match key collides with another Rule, same check POST runs on create. Patching a Rule to the match config it already has is not a collision. Returns a RuleOperationResponseInstance.
%body is sent as JSON. It takes the names Twilio's API documentation uses.
The options are:
idempotency_key-
Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
delete
$client->webhooks->v1->rules($rule_id)->delete(\%options);
Permanently deletes a Rule. Returns 202 Accepted; the deletion propagates globally in 30-60 seconds. Poll the returned Operation-Id for completion. Returns a RuleOperationResponseInstance.
The options are:
idempotency_key-
Idempotency key for mutation operations. Must be a UUIDv7 (other UUID versions are rejected with a 400).
RuleInstance
See also Twilio::InstanceResource.
It has fetch, patch and delete, which work as they do on the context.
Its fields are:
- created_at
-
A Time::Piece object in UTC. See "date_time" in Twilio::Deserialize.
- description
-
Optional description of the Rule's purpose and usage
- friendly_name
-
Human-readable name for identification
- id
-
Unique Rule identifier (TypeID/TTID format)
- match_type
-
Must be
PREFIX_MATCH. - prefix
-
URL prefix to match. Must be unique - only one rule per prefix allowed. Example: 'https://api.example.com/webhooks/'
- settings
-
Settings to apply with traffic distribution (percentages must sum to 100)
- updated_at
-
A Time::Piece object in UTC. See "date_time" in Twilio::Deserialize.
- value
-
Exact URL to match. Must be unique - only one rule per value allowed. Example: 'https://api.example.com/webhooks/voice/incoming'
RuleOperationResponseInstance
Returned by create, patch and delete, for an answer that is not a Rule. See also Twilio::InstanceResource.
Its fields are:
- operation
-
Operation tracking object — poll statusUrl for completion
- rule
-
State of the Rule resource at the time the operation was accepted (omitted for DELETE)
CONSTRUCTORS
new
Objects here come from the methods above, so there is no need to call new directly.
LICENSE
Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.