{"_id":"58a6a212a51cb62f00895153","project":"55c8cff571d7580d0063a5e5","__v":1,"parentDoc":null,"category":{"_id":"58a68ebf3239fa0f00857619","project":"55c8cff571d7580d0063a5e5","__v":0,"version":"57624356653c2d2200fec79c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-17T05:48:47.118Z","from_sync":false,"order":9,"slug":"account-listeners","title":"Account Event Listeners"},"githubsync":"","version":{"_id":"57624356653c2d2200fec79c","__v":21,"project":"55c8cff571d7580d0063a5e5","createdAt":"2016-06-16T06:12:38.244Z","releaseDate":"2016-06-16T06:12:38.244Z","categories":["57624356653c2d2200fec79d","57624356653c2d2200fec79e","57624356653c2d2200fec79f","57624356653c2d2200fec7a0","57624356653c2d2200fec7a1","57624356653c2d2200fec7a2","57624356653c2d2200fec7a3","57624356653c2d2200fec7a4","57624356653c2d2200fec7a5","57624356653c2d2200fec7a6","57624356653c2d2200fec7a7","57624356653c2d2200fec7a8","57624356653c2d2200fec7a9","57624356653c2d2200fec7aa","5779ca1b99b40b0e005abb3a","5779d198aea88b0e00f63277","5797d3ab17ced017003c4be4","57ac170ef1cdae0e0053cdfc","57dbfc723ed3450e00dc9e6d","5804d12d16161c0f0077df9b","5841064b652e5b0f0015a7c8","588b5e5f2966b2230009cbf9","58a68ebf3239fa0f00857619","58c23c8b4922930f0050ac91","58fd1460809fc30f00f2ee07","5934eaf5328680002d77de6a","594bf91601cfe6000f40f4c5","595c4ed696b447001ba0cf6d","596524495cee50001575f5be","5970d4f1313162004dd303b5","59780fac24dbd1001a1fa057","59a8cfd3ead78a002d63cafe","59e0323d93da1f001c9ec170","5b0c16f2be9fcb0003e28222"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"4.0.0","version":"4"},"user":"56f99ab84d2b4f3400edb636","updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-02-17T07:11:14.547Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"examples":{"codes":[{"code":"<?php\n\n$curl = curl_init();\n\ncurl_setopt_array($curl, array(\n    CURLOPT_URL => \"https://api.phone.com/v4/accounts/337171/listeners\",\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_ENCODING => \"\",\n    CURLOPT_MAXREDIRS => 10,\n    CURLOPT_TIMEOUT => 10,\n    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n    CURLOPT_CUSTOMREQUEST => \"POST\",\n    CURLOPT_POSTFIELDS => '{\n        \"type\" : \"callback\", \n        \"event_type\" : \"call.new\", \n        \"callbacks\" : [{ \n            \"role\" : \"main\", \n            \"url\": \"https://www.myweb.com/call_handler.php\", \n            \"verb\": \"POST\" \n        }]\n    }',\n    CURLOPT_HTTPHEADER => array(\n        \"authorization: Bearer thisIsYourAPIToken\",\n        \"cache-control: no-cache\",\n        \"content-type: application/json\"\n    ),\n));\n\n$response = curl_exec($curl);\n$err = curl_error($curl);\n\ncurl_close($curl);\n\nif ($err) {\n    echo \"cURL Error #:\" . $err;\n} else {\n    echo $response;\n}","language":"php","name":"PHP"},{"code":"<?php\n\nrequire 'vendor/autoload.php';\nuse GuzzleHttp\\Client;\n\n//-------------------------------------\n//--- Create a listener for account ---\n//-------------------------------------\n$client = new \\GuzzleHttp\\Client([\n    'base_uri' => 'https://api.phone.com/v4/',\n    'headers' => ['Authorization' => 'Bearer 12345',\n                  'Content-Type' => 'application/json'\n                 ]\n\ntry {\n    $response = $client->post(\"accounts/1/listeners\", ['json' => [\n        'type' => 'callback',\n        'event_type' => 'call.new',\n        'callbacks'  => [\n            [\n                'url' => 'https://example.com/calypso',\n                'role' => 'main',\n                'verb' => 'POST',\n                'username' => 'user123',\n                'password' => 'user123pwd',\n                'timeout' => 30\n            ]\n        ]\n    ]]);\n\n    echo $response->getBody();\n\n} catch (\\GuzzleHttp\\Exception\\ClientException $e) {\n    echo $e->getResponse()->getBody()->getContents();\n}","language":"php"}]},"method":"post","results":{"codes":[{"language":"json","code":"{\n    \"id\": 4,\n    \"voip_id\": 1,\n    \"type\": \"callback\",\n    \"event_type\": \"call.new\",\n    \"callbacks\": array [\n        \"url\": \"https://example.com/calypso\",\n        \"role\": \"main\",\n        \"verb\": \"POST\",\n        \"username\": \"user123\",\n        \"password\": \"**********\",\n        \"timeout\": 10,\n        \"verb\": \"POST\",\n    ]\n}","name":"","status":201}]},"settings":"","auth":"required","params":[{"_id":"56f9c415338fbb2000ec3711","ref":"","in":"path","required":false,"desc":"Account ID","default":"","type":"int","name":"account_id"},{"_id":"579be149f4ad7b190094b6cd","ref":"","in":"body","required":true,"desc":"Type of listener.  Must be 'callback'","default":"","type":"string","name":"type"},{"_id":"579be1c7f4ad7b190094b6d0","ref":"","in":"body","required":true,"desc":"Type of event to subscribe.  'call.new', 'call.update', 'call.complete'","default":"","type":"string","name":"event_type"},{"_id":"579be1c7f4ad7b190094b6cf","ref":"","in":"body","required":true,"desc":"Array of [Callback Objects](doc:account-listeners#section-callback-object).","default":"","type":"array_object","name":"callbacks"}],"url":"/accounts/:account_id/listeners"},"isReference":false,"order":3,"body":"This service creates an individual listener object. See [Account Listeners](doc:account-listeners) for more info on the properties.","excerpt":"Add a listener object to your account that can be used to subscribe an event.  See [Account Listeners](doc:account-listeners) for more info on the properties.\n\nNote: This API is for users with Account Owner scope access token. Users with Extension User scope token should invoke the Extension level Post Listener API with the following definition:\n\nPOST https://api.phone.com/v4/accounts/:account_id/extensions/:extension_id/listeners","slug":"create-account-listener","type":"endpoint","title":"Create Listener"}

postCreate Listener

Add a listener object to your account that can be used to subscribe an event. See [Account Listeners](doc:account-listeners) for more info on the properties. Note: This API is for users with Account Owner scope access token. Users with Extension User scope token should invoke the Extension level Post Listener API with the following definition: POST https://api.phone.com/v4/accounts/:account_id/extensions/:extension_id/listeners

Definition

{{ api_url }}{{ page_api_url }}

Parameters

Path Params

account_id:
integer
Account ID

Body Params

type:
required
string
Type of listener. Must be 'callback'
event_type:
required
string
Type of event to subscribe. 'call.new', 'call.update', 'call.complete'
callbacks:
required
array of objects
Array of [Callback Objects](doc:account-listeners#section-callback-object).

Examples


Result Format


Documentation

This service creates an individual listener object. See [Account Listeners](doc:account-listeners) for more info on the properties.

User Information

Try It Out

post
{{ tryResults.results }}
Method{{ tryResults.method }}
Request Headers
{{ tryResults.requestHeaders }}
URL{{ tryResults.url }}
Request Data
{{ tryResults.data }}
Status
Response Headers
{{ tryResults.responseHeaders }}