Event subscriptions (webhooks)
Overview
Allows you to manage subscriptions to events generated by the system.
Applies only to requests authorized through tokens integration channels with type subscr
.
Based on the subscription results, the system sends webhooks to the address specified in the url
field of the integration channel.
The subscription requires regular renewal at intervals not exceeding the subscription registration period specified in the request (field expires
).
An arbitrary number of subscriptions can be registered through one integration channel. But each event is sent no more than once to a single integration channel, treating one integration channel entity as one separate instance of the external system. All it takes is one active subscription setting the conditions for sending an event to the current integration channel, suitable for the generated event instance, for it to be sent by the webhook.
At any time, a subscription can be terminated by a deletion request.
In the current version, subscriptions are only valid for the following classes of events:
-
callevents
-
confevents
-
providerevents
-
statesevents
-
Custom events from scripts
Available in working domains only.
Requests
HTTP verb | Endpoint | Description |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
Subscribe to events
Produces event subscriptions. The subscription ID is returned in the response and can be used to renew and delete subscriptions.
Request
Field | Description |
---|---|
|
Filter by objects to which generated events are bound. For an event to be sent by subscription, it must be bound to at least one of the specified objects. For example, if the user specified in the filter is a participant in the call for which the event is generated, the subscription event will be sent. Otherwise it will not. Specified as a JSON array of objects applied via an |
|
A list of events to be sent by webhooks. Specified as a JSON array of strings.
Each line represents a mask for the event in the format |
|
Subscription registration period, in seconds. If there are no renewals after the interval, the subscription is automatically deleted.
Maximum value: |
|
Arbitrary URL to send webhooks to. Optional parameter. The |
Event Class | Object type (field type) | Filter fields by object |
---|---|---|
|
|
Account login SIP-user |
|
|
Subscriber’s phone number |
|
|
Room ID or room number conferences |
|
|
Account code telephony provider |
|
|
|
|
|
|
|
|
Account login SIP-user |
POST /rest/v1/service/webhooks HTTP/1.1
Content-Type: application/json
Authorization: Bearer 522f62e0b5e731cd507e20bc888c53d5
{
"objects": [
{
"type":"sipuser",
"sipuser":"sip1"
},
{
"type":"sipuser",
"sipuser":"sip2"
}
],
"events": [
"callevents.*",
"statesevents.sipuser_state_changed"
],
"expires": 1800
}
Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"id": "4e7e9ce0-0621-6606-d157-c00000000004",
"msg": "subscribed"
}
404 Not Found
Content-Type: application/json
{
"error_code": 1404,
"error_message": "Token not found"
}
Subscription information
Displays subscription information by ID.
Request
GET /rest/v1/service/webhooks/4e7e9ce0-0621-6606-d157-c00000000004 HTTP/1.1
Authorization: Bearer 522f62e0b5e731cd507e20bc888c53d5
Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"objects": {"sipuser": "sip2", "sipuser": "sip1"},
"events":["callevents.*", "statesevents.sipuser_state_changed"],
"url": "http://127.0.0.1"
}
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[]
404 Not Found
Content-Type: application/json
{
"error_code": 1404,
"error_message": "Token not found"
}
Event subscription renewal
Produces event subscription renewals. Allows changes to the terms and conditions of a previous subscription.
Request
The object fields are similar to query fields POST.
PUT /rest/v1/service/webhooks/4e7e9ce0-0621-6606-d157-c00000000004 HTTP/1.1
Content-Type: application/json
Authorization: Bearer 522f62e0b5e731cd507e20bc888c53d5
{
"objects": [
{
"type":"sipuser",
"sipuser":"sip1"
},
{
"type":"sipuser",
"sipuser":"sip2"
}
],
"events": [
"callevents.*"
],
"expires": 1800
}
Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"id": "4e7e9ce0-0621-6606-d157-c00000000004",
"msg": "subscribed"
}
404 Not Found
Content-Type: application/json
{
"error_code": 1404,
"error_message": "Token not found"
}
See also
-
Scripts component Generate arbitrary event.
-
Entity integration channel
-
Subscription to events via websocket connection