[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 ============== 2 Usage Triggers 3 ============== 4 5 Twilio offers a Usage Trigger API so you can get notifications when your Twilio 6 usage exceeds a given level. Here are some examples of how you can 7 use PHP to create new usage triggers or modify existing triggers. 8 9 Retrieve A Usage Trigger's Properties 10 ===================================== 11 12 If you know the Sid of your usage trigger, retrieving it is easy. 13 14 .. code-block:: php 15 16 $client = new Services_Twilio('AC123', '456bef'); 17 $usageSid = 'UT123'; 18 $usageTrigger = $client->account->usage_triggers->get($usageSid); 19 echo $usageTrigger->usage_category; 20 21 Update Properties on a UsageTrigger 22 =================================== 23 24 .. code-block:: php 25 26 $client = new Services_Twilio('AC123', '456bef'); 27 $usageSid = 'UT123'; 28 $usageTrigger = $client->account->usage_triggers->get($usageSid); 29 $usageTrigger->update(array( 30 'FriendlyName' => 'New usage trigger friendly name', 31 'CallbackUrl' => 'http://example.com/new-trigger-url', 32 )); 33 34 Retrieve All Triggers 35 ===================== 36 37 .. code-block:: php 38 39 $client = new Services_Twilio('AC123', '456bef'); 40 foreach ($client->account->usage_triggers as $trigger) { 41 echo "Category: {$trigger->usage_category}\nTriggerValue: {$trigger->trigger_value}\n"; 42 } 43 44 Filter Trigger List By Category 45 =============================== 46 47 Pass filters to the `getIterator` function to create a filtered list. 48 49 .. code-block:: php 50 51 $client = new Services_Twilio('AC123', '456bef'); 52 foreach ($client->account->usage_triggers->getIterator( 53 0, 50, array( 54 'UsageCategory' => 'sms', 55 )) as $trigger 56 ) { 57 echo "Value: " . $trigger->trigger_value . "\n"; 58 } 59 60 Create a New Trigger 61 ==================== 62 63 Pass a usage category, a value and a callback URL to the `create` method. 64 65 .. code-block:: php 66 67 $client = new Services_Twilio('AC123', '456bef'); 68 $trigger = $client->account->usage_triggers->create( 69 'totalprice', 70 '250.75', 71 'http://example.com/usage' 72 ); 73 74 Create a Recurring Trigger 75 ========================== 76 77 To have your trigger reset once every day, month, or year, pass the 78 `Recurring` key as part of the params array. A list of optional 79 trigger parameters can be found in the `Usage Triggers Documentation 80 <http://www.twilio.com/docs/api/rest/usage-triggers#list-post-optional-paramete 81 rs>`_. 82 83 .. code-block:: php 84 85 $client = new Services_Twilio('AC123', '456bef'); 86 $trigger = $client->account->usage_triggers->create( 87 'totalprice', 88 '250.75', 89 'http://example.com/usage', 90 array('Recurring' => 'monthly', 'TriggerBy' => 'price') 91 ); 92
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |