Протестировать методы API можно на странице интерактивного обозревателя API и без написания кода
Некоторые ресурсы, описанные на странице, по умолчанию могут быть не доступны из-за типа приложения (см. Создание и авторизация приложений)
Описание структур данных
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Правило входящего вызова (IncomingRule)
Последовательность правил (IncomingRuleOrder)
|
Примеры
Настроим правила для внутреннего номера типа "phone"с идентификатором 54. Для начала убедимся, что на данный момент нет никаких настроек:
Tabs |
---|
[{"content":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"В разделе "},{"type":"text","text":"authentication","marks":[{"type":"strong"}]},{"type":"text","text":" в поля "},{"type":"text","text":"client_id","marks":[{"type":"strong"}]},{"type":"text","text":" и "},{"type":"text","text":"client_secret","marks":[{"type":"strong"}]},{"type":"text","text":" требуется ввести полученные при регистрации приложения значения "},{"type":"text","text":"Application_ID","marks":[{"type":"strong"}]},{"type":"text","text":" и "},{"type":"text","text":"Application_Secret","marks":[{"type":"strong"}]},{"type":"text","text":", затем нажать на кнопку \""},{"type":"text","text":"Try it out!","marks":[{"type":"strong"}]},{"type":"text","text":"\". Если данные приложения верны, в ответ вернётся токен доступа ("},{"type":"text","text":"access_token","marks":[{"type":"strong"}]},{"type":"text","text":"). Полученный токен доступа следует ввести в поле \""},{"type":"text","text":"Access Token Field","marks":[{"type":"strong"}]},{"type":"text","text":"\" вверху страницы и сохранить его нажатием кнопки \""},{"type":"text","text":"Set Token","marks":[{"type":"strong"}]},{"type":"text","text":"\"."}]},{"type":"table","attrs":{"isNumberColumnEnabled":false,"layout":"default"},"content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"метод","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"ресурс","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"данные","marks":[{"type":"strong"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"GET"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"/extension/54/incom_rule/"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[]}]}]}]},{"type":"paragraph","content":[]}]},"id":"57483245-8bbc-4e63-978a-8ba21ea01a9d","label":"Интерактивный обозреватель API ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Для отправки запросов с помощью программы cURL установим значения переменных "},{"type":"text","text":"url ","marks":[{"type":"strong"}]},{"type":"text","text":"и "},{"type":"text","text":"access_token","marks":[{"type":"strong"}]},{"type":"text","text":":"}]},{"type":"paragraph","content":[{"type":"text","text":"export url=\"https://<hostname>/api/ver1.0\"","marks":[{"type":"code"}]},{"type":"text","text":" "},{"type":"hardBreak"},{"type":"text","text":"(где hostname — hostname API-сервера провайдера IP-телефонии),"}]},{"type":"paragraph","content":[{"type":"text","text":"export access_token=\"8SNsrS0jV35vfmKqKeKtRrHfpbg4UX\"","marks":[{"type":"code"}]},{"type":"text","text":" "},{"type":"hardBreak"},{"type":"text","text":"(полученный токен доступа)."}]},{"type":"paragraph","content":[{"type":"text","text":"Отправим запрос:"}]},{"type":"codeBlock","attrs":{"language":"shell"},"content":[{"type":"text","text":"curl \\\n-H \"Authorization: Bearer ${access_token}\" \\\n-X GET ${url}/extension/54/incom_rule/"}]}]},"id":"74ca4e70-1342-4b06-88c7-104c8b6c4029","label":"Программа cURL ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Для отправки запросов на языке Python установим значения переменных URL и ACCESS_TOKEN:"}]},{"type":"paragraph","content":[{"type":"text","text":"URL = \"https://<hostname>/api/ver1.0\"","marks":[{"type":"code"}]},{"type":"hardBreak"},{"type":"text","text":"(где hostname — hostname API-сервера провайдера IP-телефонии),"}]},{"type":"paragraph","content":[{"type":"text","text":"ACCESS_TOKEN = \"8SNsrS0jV35vfmKqKeKtRrHfpbg4UX\"","marks":[{"type":"code"}]},{"type":"hardBreak"},{"type":"text","text":"(полученный токен доступа)."}]},{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"#!/usr/bin/python\n\nimport requests\n\nurl = f'{URL}/extension/54/incom_rule/'\nheaders = {\n 'Authorization': f'Bearer {ACCESS_TOKEN}'\n}\nresponse = requests.get(url, headers=headers)\nprint(response.text)"}]}]},"id":"2a641f9b-de12-47fa-8a66-84e4ed6c529d","label":"На языке Python3 ","type":"tab"}] |
Ответ системы:[]
Переадресация
Настроим отправку всех неотвеченных вызовов на номер 00018966 ("type:" "transfer"). Правило должно будет действовать только с 10:00 до 20:00 и распространяться на вызовы с номеров, начинающихся на "+7812" или "000". Номер 00018966 должен звонить 15 секунд.
Время, после которого вызов на внутренний номер считается неотвеченным (hangup-timeout), является свойством самого внутреннего номера типа 'phone' и настраивается ресурсом “Телефонный терминал (/phone/)”.
Для начала нужно создать (или выбрать из имеющихся) временной интервал. Пусть это будет интервал с идентификатором 32. Создание правила:
Tabs |
---|
[{"content":{"version":1,"type":"doc","content":[{"type":"table","attrs":{"isNumberColumnEnabled":false,"layout":"default"},"content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"метод","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"ресурс","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"данные","marks":[{"type":"strong"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"POST"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"/extension/54/incom_rule/"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"{"},{"type":"hardBreak"},{"type":"text","text":"\"caller_id\": \"^(\\\\+7812|000)\","},{"type":"hardBreak"},{"type":"text","text":"\"caller_id_action\": \"matches\","},{"type":"hardBreak"},{"type":"text","text":"\"interval\": 32,"},{"type":"hardBreak"},{"type":"text","text":"\"transfer_dst\": \"00018966\","},{"type":"hardBreak"},{"type":"text","text":"\"transfer_timeout\": 15,"},{"type":"hardBreak"},{"type":"text","text":"\"type\": \"transfer\","},{"type":"hardBreak"},{"type":"text","text":"\"call_status\": \"no_answer\","},{"type":"hardBreak"},{"type":"text","text":"\"final\": false"},{"type":"hardBreak"},{"type":"text","text":"}"}]}]}]}]},{"type":"paragraph","content":[]}]},"id":"57483245-8bbc-4e63-978a-8ba21ea01a9d","label":"Интерактивный обозреватель API ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"codeBlock","attrs":{"language":"shell"},"content":[{"type":"text","text":"curl \\\n-H \"Authorization: Bearer ${access_token}\" \\\n-H \"Content-Type: application/json\" \\\n-d '{\n \"caller_id\": \"^(\\\\+7812|000)\",\n \"caller_id_action\": \"matches\",\n \"interval\": 32,\n \"transfer_dst\": \"00018966\",\n \"transfer_timeout\": 15,\n \"type\": \"transfer\",\n \"call_status\": \"no_answer\",\n \"final\": false\n}' \\\n-X POST ${url}/extension/54/incom_rule/"}]}]},"id":"74ca4e70-1342-4b06-88c7-104c8b6c4029","label":"Программа cURL ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"#!/usr/bin/python\n\nimport requests\n\nurl = f'{URL}/extension/54/incom_rule/'\nheaders = {\n 'Authorization': f'Bearer {ACCESS_TOKEN}',\r\n 'Content-Type': 'application/json'\r\n}\r\ndata = '''{\r\n \"caller_id\": \"^(\\\\+7812|000)\",\n \"caller_id_action\": \"matches\",\n \"interval\": 32,\n \"transfer_dst\": \"00018966\",\n \"transfer_timeout\": 15,\n \"type\": \"transfer\",\n \"call_status\": \"no_answer\",\n \"final\": false\n}'''\r\nresponse = requests.post(url, headers=headers, data=data)\nprint(response.text)"}]}]},"id":"2a641f9b-de12-47fa-8a66-84e4ed6c529d","label":"На языке Python3 ","type":"tab"}] |
Expand | |||||
---|---|---|---|---|---|
| |||||
|
Каскадный вызов
Теперь нужно, чтобы после выполнения правил в предыдущем разделе, если ответа так и не последовало, вызов перешел на внутренний номер 000*099, через 5 секунд к нему подключился 00026821 и все правило отрабатывало не более 20 секунд:
Tabs |
---|
[{"content":{"version":1,"type":"doc","content":[{"type":"table","attrs":{"isNumberColumnEnabled":false,"layout":"default"},"content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"метод","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"ресурс","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"данные","marks":[{"type":"strong"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"POST"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"/extension/54/incom_rule/"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"{"},{"type":"hardBreak"},{"type":"text","text":"\"caller_id\": \"^(\\\\+7812|000)\","},{"type":"hardBreak"},{"type":"text","text":"\"caller_id_action\": \"matches\","},{"type":"hardBreak"},{"type":"text","text":"\"interval\": 32,"},{"type":"hardBreak"},{"type":"text","text":"\"transfer_timeout\": 20,"},{"type":"hardBreak"},{"type":"text","text":"\"type\": \"cascade\","},{"type":"hardBreak"},{"type":"text","text":"\"call_status\": \"no_answer\","},{"type":"hardBreak"},{"type":"text","text":"\"cascade_numbers\": ["},{"type":"hardBreak"},{"type":"text","text":"{"},{"type":"hardBreak"},{"type":"text","text":"\"delay\": 0,"},{"type":"hardBreak"},{"type":"text","text":"\"number\": \"000*099\""},{"type":"hardBreak"},{"type":"text","text":"},"},{"type":"hardBreak"},{"type":"text","text":"{"},{"type":"hardBreak"},{"type":"text","text":"\"delay\": 5,"},{"type":"hardBreak"},{"type":"text","text":"\"number\":\"00026821\""},{"type":"hardBreak"},{"type":"text","text":"}],"},{"type":"hardBreak"},{"type":"text","text":"\"final\": false"},{"type":"hardBreak"},{"type":"text","text":"}"}]}]}]}]},{"type":"paragraph","content":[]}]},"id":"fcebb4df-d7fb-4895-8061-8b032a6201e6","label":"Интерактивный обозреватель API ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"codeBlock","attrs":{"language":"shell"},"content":[{"type":"text","text":"curl \\\n-H \"Authorization: Bearer ${access_token}\" \\\n-H \"Content-Type: application/json\" \\\n-d '{\n \"caller_id\": \"^(\\\\+7812|000)\",\n \"caller_id_action\": \"matches\",\n \"interval\": 32,\n \"transfer_timeout\": 20,\n \"type\": \"cascade\",\n \"call_status\": \"no_answer\",\n \"cascade_numbers\": [\n {\n \"delay\": 0,\n \"number\": \"000*099\"\n },\n {\n \"delay\": 5,\n \"number\":\"00026821\"\n }\n ],\n \"final\": false\n}' \\\n-X POST ${url}/extension/54/incom_rule/"}]}]},"id":"320379f7-8bd0-4891-b4ab-ae7b5eb4aaf5","label":"Программа cURL ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"#!/usr/bin/python\r\n\r\nimport requests\r\n\r\nurl = f'{URL}/extension/54/incom_rule/'\nheaders = {\r\n 'Authorization': f'Bearer {ACCESS_TOKEN}',\r\n 'Content-Type': 'application/json'\r\n}\r\ndata = '''{\r\n \"caller_id\": \"^(\\\\+7812|000)\",\n \"caller_id_action\": \"matches\",\n \"interval\": 32,\n \"transfer_timeout\": 20,\n \"type\": \"cascade\",\n \"call_status\": \"no_answer\",\n \"cascade_numbers\":\n [\n {\n \"delay\": 0,\n \"number\": \"000*099\"\n },\n {\n \"delay\": 5,\n \"number\":\"00026821\"\n }\n ],\n \"final\": false\n}'''\r\nresponse = requests.post(url, headers=headers, data=data)\r\nprint(response.text)"}]}]},"id":"0c8e4741-8e0f-4432-a35a-8ec4dace53b2","label":"На языке Python3 ","type":"tab"}] |
Expand | |||||
---|---|---|---|---|---|
| |||||
|
Реорганизация правил
Чтобы поменять предыдущие правила местами, достаточно выполнить:
Tabs |
---|
[{"content":{"version":1,"type":"doc","content":[{"type":"table","attrs":{"isNumberColumnEnabled":false,"layout":"default"},"content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"метод","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"ресурс","marks":[{"type":"strong"}]}]}]},{"type":"tableHeader","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"данные","marks":[{"type":"strong"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"PUT"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"/extension/54/incom_rule/order/"}]}]},{"type":"tableCell","attrs":{},"content":[{"type":"paragraph","content":[{"type":"text","text":"{"},{"type":"hardBreak"},{"type":"text","text":"\"rules_ids\": ["},{"type":"hardBreak"},{"type":"text","text":"2,1"},{"type":"hardBreak"},{"type":"text","text":"]"},{"type":"hardBreak"},{"type":"text","text":"}"}]}]}]}]},{"type":"paragraph","content":[]}]},"id":"540d5c49-33e2-44ff-a4b6-6374821a52bf","label":"Интерактивный обозреватель API ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"codeBlock","attrs":{"language":"shell"},"content":[{"type":"text","text":"curl \\\n-H \"Authorization: Bearer ${access_token}\" \\\n-H \"Content-Type: application/json\" \\\n-d '{\"rules_ids\": [2,1]}' \\\n-X PUT ${url}/extension/54/incom_rule/order/"}]}]},"id":"1cdab8a9-a005-426c-a31d-4a77a3d4c9fb","label":"Программа cURL ","type":"tab"},{"content":{"version":1,"type":"doc","content":[{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"#!/usr/bin/python\r\n\r\nimport requests\r\n\r\nurl = f'{URL}/extension/54/incom_rule/order/'\r\nheaders = {\r\n 'Authorization': f'Bearer {ACCESS_TOKEN}',\r\n 'Content-Type': 'application/json'\r\n}\r\ndata = '''{\n \"rules_ids\": [2,1]\r\n}'''\r\nresponse = requests.put(url, headers=headers, data=data)\r\nprint(response.text)"}]}]},"id":"194e938f-cf31-46c1-a6b5-182cf4875a8d","label":"На языке Python3 ","type":"tab"}] |
Ответ системы:
Code Block | ||
---|---|---|
| ||
{ "rules_ids": [ 2, 1 ] } |
Ресурсы раздела “Внутренний номер”
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
POST /extension/{extension_id}/incom_rule/ Добавить правило входящего вызова внутреннего номера Параметры URL
Параметры JSON
cascade_number
Поля ответа
cascade_number
|
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||
GET /extension/{extension_id}/incom_rule/ Получить список правил входящего вызова внутреннего номера Параметры URL
Поля ответа
cascade_number
|
Expand | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||
PUT /extension/{extension_id}/incom_rule/order/ Обновить порядок правил входящего вызова внутреннего номера Параметры URL
Параметры JSON
Поля ответа
|
Expand | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
GET /extension/{extension_id}/incom_rule/order/ Получить порядок правил входящего вызова внутреннего номера Параметры URL
Поля ответа
|
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PUT /extension/{extension_id}/incom_rule/{rule_id} Обновить правило входящего вызова внутреннего номера Параметры URL
Параметры JSON
cascade_number
Поля ответа
cascade_number
|
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
GET /extension/{extension_id}/incom_rule/{rule_id} Получить правило входящего вызова внутреннего номера Параметры URL
Поля ответа
cascade_number
|
Expand | ||||||
---|---|---|---|---|---|---|
| ||||||
DELETE /extension/{extension_id}/incom_rule/{rule_id} Удалить правило входящего вызова внутреннего номера Параметры URL
|