Telephony API
The Telephony API lets an application work with calls while they happen. It can see who is available, ringing or on a call; place a call from someone’s phone; transfer, park, pick up, hang up or record a call; take a caller out of a queue; and receive an event the moment a call rings, is answered or ends. A CRM can open the caller’s record when a phone rings, a wallboard can show who is on the phone, and a helpdesk tool can offer click-to-call.
Why you would want it
The REST API manages configuration: extensions, queues, routes. It does not show calls in progress or act on them. Without the Telephony API, an application that needs live call information either polls call history after the fact or is given administrator credentials that allow far more than it needs.
The Telephony API gives each application its own key, limited to the calls it should see and the actions it should take, and lets you revoke that key without affecting anything else.
How it works
Who a key acts as
Every request carries an API key in the X-API-Key header. There are two kinds of key:
- Personal key - acts as the person who owns it, with the same rights that person has in the Team Panel: full control of their own calls, plus whatever the preset, their role and the rules give them over colleagues. Only a person with an extension can use a personal key with the Telephony API.
- Integration key - belongs to the organization and is meant for an application such as a CRM or a wallboard. It starts with no rights at all. It gets rights only from Team Panel rules whose Who is that key, so you decide exactly which people, park lots and queues it covers and what it may do there. The preset and roles do not apply to it, but each person’s privacy settings do: a key never sees someone hidden from the Team Panel, or the other party of someone who hides it.
The same checks run whether a call is moved from the Team Panel or through the API.
What a key may be used for
Each key has Scopes, chosen when it is created:
| Scope | Allows |
|---|---|
| Read live call state | Reading people, calls, parked calls, queues and destinations |
| Control calls | Placing, transferring, parking, picking up, hanging up and recording calls |
| Receive live call events | Opening the live event stream |
| Configuration API | The REST API for configuration |
A key needs both the scope and the Team Panel right. For example, a key with Control calls can transfer a colleague’s call only if a rule gives it Transfer their calls over that colleague.
Live events
Events reach an application in two ways:
- Outbound webhooks - the system posts each event to a URL you choose. Webhooks are not limited by a key: they receive every event of the organization they subscribe to.
- The event stream - the application keeps a WebSocket connection open with its key and receives only what that key may see. On connecting it receives the current state, then every change, numbered in order. If a number is skipped, a message was lost; reconnecting gives fresh state.
The call events are call.ringing, call.dialing, call.answered, call.held, call.resumed, call.transferred, call.parked, call.retrieved, call.queue_joined, call.queue_left, call.ended (with the outcome: answered, missed, voicemail or not connected), call.completed, call.missed, and presence.changed.
How to set it up
1. Turn the Telephony API on
A system administrator opens the organization in Platform > Accounts > Organizations, goes to the Features and Limits tab, and checks Telephony API. It is off by default and takes effect within a minute.
2. Create a key
For an application, create an Integration key: open Organization > Integrations & SSO > API Keys (system administrators can also use Platform > API Keys (Global)), click Add, set Type to Integration, and choose its Scopes - for example Read live call state and Receive live call events for a wallboard. On a system with several organizations an integration key must be bound to one organization. Optionally set Expires.
Copy the key when it is shown; it is not shown again.
A person who wants to use their own phone from a script can create a Personal key under User Portal > Settings > API Keys.
3. Give an integration key its rights
Open Organization > Connect > Team Panel > Rules and add a rule with Who = Integration key and the key you created. For a wallboard of the Sales department:
- Who: Integration key Sales wallboard
- Over: Department Sales
- Rights: See whether on the phone, See who they are talking to
4. Make a request
List the people the key can see:
curl -H "X-API-Key: YOUR_API_KEY" https://pbx.example.com/api/telephony/v1/usersPlace a call from extension 100 to a customer:
curl -X POST -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{"from":"100","to":"+12025559876"}' https://pbx.example.com/api/telephony/v1/callsExtension 100’s phone rings first; when it is answered, the system dials the number with extension 100’s own dialing permissions. If extension 100 does not answer, or has no phone connected, the call is not placed: the first leg does not go to that extension’s voicemail or call forwarding. A person can be named by extension number, as here, or by the user name returned by /users.
Transfer a call to extension 200:
curl -X POST -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{"target":{"type":"extension","name":"200"}}' https://pbx.example.com/api/telephony/v1/calls/1761240000.42/transferOpen the event stream at wss://pbx.example.com/api/telephony/v1/events, sending the key in the X-API-Key header. Where a WebSocket client cannot set headers, pass it as the api_key query parameter instead.
The full reference, with every endpoint and field, is under Platform > General Settings & Tools > Tools > OpenAPI REST, in the Telephony API section.
Operating it
- Where calls can go. A transfer goes where the Team Panel can send calls: a person, their voicemail, a park lot, or an entry on Organization > Connect > Team Panel > Destinations - a queue, Hunt Group, IVR, conference room, special mailbox, feature extension allowed to take calls, or outside number. Other numbers are refused.
GET /api/telephony/v1/destinationslists them, andGET /api/telephony/v1/queueslists the queues on that list. - Limits. Each key may make 600 requests a minute and 10 actions a second, and keep 5 event streams open. Over a limit, the answer is
429with aRetry-Afterheader giving the seconds to wait. - Errors.
401means the key is missing, unknown, revoked or expired.403means the key lacks the scope or the right, or the Telephony API is off.404means the call has ended or the key may not see it.409means the call is in a state that does not allow the action, for example picking up a call that is no longer ringing. - Revoking a key. Open the key and check Revoked. It is refused everywhere within 30 seconds. Clearing the checkbox makes it work again.
- Live call events need live state. Call and presence events exist only for organizations with the Telephony API or the Team Panel turned on.
Best practices
- Create one integration key per application, so each can be revoked on its own.
- Give a key only the scopes it uses. A wallboard needs Read live call state and Receive live call events, not Control calls.
- Start rules for a key narrow - one department or one queue - and widen them as needed.
GET /api/telephony/v1/userswith the key shows exactly whom it can see. - Use an expiry date for keys given to contractors or trials.
- Prefer the event stream or webhooks to polling
/calls; they deliver each change as it happens and use far fewer requests.
Related documentation
- Team Panel - the presets, roles and rules that decide what a key may see and do.
- Outbound Webhooks - receiving call events at a URL.
- REST API - configuration through the API.
- API Keys - creating personal keys in the User Portal.