Skip to main content

Phone Numbers API

The Phone Numbers API lists, adds, deletes, links and unlinks the phone numbers in your workspace from your own system. It does what the Phone Numbers screen does: a number you add here appears there, and the other way round. Linking does what picking a number in an agent's Call Configuration does.

When to Use This​

  • Look up a number's phone_uuid to start a campaign from it.
  • Add the numbers you buy at Twilio, Plivo or Vobiz without opening DronaHQ.
  • Link a number to an agent, so the agent answers calls to it or calls from it.
  • Take a number away from an agent, or out of the workspace, when you stop using it.

This API can't change a number once it is added. To change a number's label or credentials, delete it and add it again.

Prerequisites​

  • An API Key with the Phone numbers scope.
  • The older Voice Agent scope doesn't give access to this API. To use an older key that has only Voice Agent, edit it under Developer → API Keys and add the Phone numbers scope.
  • The key's Agent Access decides which numbers it reaches. See Keys limited to some agents.

Authentication​

Every request must include your key, in the api-key header or as a Bearer token. See API Keys for how to create one. The examples on this page use api-key.

api-key: sk_<your-secret>

or

Authorization: Bearer sk_<your-secret>

Every request made with one of your keys is recorded in Request Logs, including the failures.

Base path

These endpoints are served at the root of your DronaHQ host: https://<your-dronahq-host>/voice/phone_numbers. There is no /api/v1 prefix, and the path uses an underscore.

Endpoints​

MethodPathWhat it does
GET/voice/phone_numbersList numbers
GET/voice/phone_numbers/{phone_uuid}Get a number
GET/voice/phone_numbers/providersList providers
POST/voice/phone_numbersAdd a number
DELETE/voice/phone_numbers/{phone_uuid}Delete a number
POST/voice/phone_numbers/{phone_uuid}/linkLink a number to an agent
POST/voice/phone_numbers/{phone_uuid}/unlinkUnlink agents from a number

A number has two ids, and the other APIs take different ones:

FieldExampleTaken by
phone_uuide5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63This API's paths, and Campaigns as from_phone_uuid
phone_number+14155550100Outbound Call Dispatch as source_phone_number

Keys limited to some agents​

A number belongs to the workspace, not to one agent, so a key set to All Agents reaches every number. A key limited to specific agents reaches what its agents use:

The keyWhich numbers
SeesNumbers linked to one of its agents, and numbers linked to no agent: the numbers its agents can call from. A number linked only to other agents is left out of the list, and a request for it fails with 403
AddsAny number. A new number is linked to no agent
DeletesA number whose linked agents are all on its list, and that no other agent receives inbound calls on. Otherwise it's a 403, because deleting it would take it away from them
LinksA number it sees, to one of its own agents. Naming another agent is a 403
UnlinksIts own agents only. Naming another agent is a 403

In what it returns, the key sees only its own agents: agents leaves the others out, and inbound_taken_by is null when another agent holds the number. The same goes for a refused link: the error names the agent that already answers on the number only when the key can access that agent.


List numbers​

GET /voice/phone_numbers

Returns every number the key can see, most recently added first. There are no parameters and no pagination.

curl https://<your-dronahq-host>/voice/phone_numbers \
-H "api-key: sk_your-generated-secret-here"

Response — 200 OK​

{
"status": "success",
"count": 2,
"phone_numbers": [
{
"phone_uuid": "e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63",
"phone_number": "+14155550100",
"label": "US support line",
"provider": "twilio",
"agents": [
{ "agent_uuid": "3b7e1c2a-5d4f-4e8a-9b6c-0f1e2d3c4b5a", "agent_name": "Order Helper" }
],
"is_linked": true,
"capabilities": { "voice": true, "sms": true, "mms": true, "fax": false, "sms_enabled": true },
"sip_trunk_uuid": null,
"inbound_taken_elsewhere": true,
"inbound_taken_by": "3b7e1c2a-5d4f-4e8a-9b6c-0f1e2d3c4b5a"
},
{
"phone_uuid": "7c41a9e0-2b8d-4f63-a51e-9d0c3b6f2e18",
"phone_number": "+918045550123",
"label": null,
"provider": "plivo",
"agents": [],
"is_linked": false,
"capabilities": { "voice": true, "sms": false, "mms": false, "fax": false, "sms_enabled": false },
"sip_trunk_uuid": null,
"inbound_taken_elsewhere": false,
"inbound_taken_by": null
}
]
}
FieldDescription
phone_uuidThe number's id. See the two ids
phone_numberThe number in E.164
labelThe name you gave it, or null
providertwilio, plivo, vobiz or sip
agentsThe agents the number is linked to, with their names. Only agents the key can access are listed
is_linkedtrue when the number is linked to any agent, including agents the key can't access
capabilitiesWhat the number can do, as the provider reported it when the number was added: voice, sms, mms, fax. sms_enabled is the value you sent on add. The builder's SMS tool offers a number when sms or sms_enabled is true
sip_trunk_uuidFor a sip number, the SIP trunk it calls through. Otherwise null
inbound_taken_elsewheretrue when an agent already answers inbound calls on this number. A number answers inbound calls for one agent only; outbound calls from it aren't affected
inbound_taken_byThe agent that answers them, or null if none does or the key can't access it

Provider credentials are stored encrypted and are never returned.


Get a number​

GET /voice/phone_numbers/{phone_uuid}

Returns one number, in the same shape as an item of List numbers.

curl https://<your-dronahq-host>/voice/phone_numbers/e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63 \
-H "api-key: sk_your-generated-secret-here"

Response — 200 OK​

{
"status": "success",
"phone_number": {
"phone_uuid": "e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63",
"phone_number": "+14155550100",
"label": "US support line",
"provider": "twilio",
"…": "…"
}
}

A number that isn't in the key's workspace is a 404, and so is a phone_uuid that isn't a valid UUID.


List providers​

GET /voice/phone_numbers/providers

Returns the telephony providers, by name. A number can be added for a provider whose is_supported is true. Use its provider_id as provider when you add a number.

curl https://<your-dronahq-host>/voice/phone_numbers/providers \
-H "api-key: sk_your-generated-secret-here"

Response — 200 OK​

{
"status": "success",
"providers": [
{
"provider_id": "twilio",
"provider_name": "Twilio",
"short_description": "…",
"supports_sip": true,
"supports_sms": true,
"is_supported": true
}
]
}

Add a number​

POST /voice/phone_numbers

Adds a number you already own at a provider, as Add Phone Number does in the app. DronaHQ checks the credentials with the provider before it saves anything, so a wrong token or a number that isn't on the account fails with 400 and nothing is added.

Body​

FieldTypeRequiredDescription
providerstringYestwilio, plivo, vobiz or sip. See List providers
phone_numberstringYesThe number in E.164, for example +14155550100
auth_configobjectYesThe provider's credentials. See below. Every value is a string
labelstringNoA name for the number, up to 128 characters
country_codestringNoThe number's two-letter country code, for example US. Up to 8 characters
country_labelstringNoThe country's name. Up to 128 characters
sms_enabledbooleanNotrue marks the number as able to send SMS, for when the provider doesn't report it. Default false. Ignored for a sip number, which can't send SMS

An unknown field is rejected with 422, so a misspelt field fails loudly.

providerauth_config
twilioaccount_sid, auth_token
plivoauth_id, auth_token
vobizauth_id, auth_token
sipsip_trunk_uuid: a SIP trunk set up in the app under SIP Trunking. The number is registered on the trunk. See SIP trunks

Where to find these credentials at each provider is in the telephony guides.

Example request​

curl -X POST https://<your-dronahq-host>/voice/phone_numbers \
-H "api-key: sk_your-generated-secret-here" \
-H "Content-Type: application/json" \
-d '{
"provider": "twilio",
"phone_number": "+14155550100",
"label": "US support line",
"country_code": "US",
"sms_enabled": true,
"auth_config": {
"account_sid": "AC00000000000000000000000000000000",
"auth_token": "<your-twilio-auth-token>"
}
}'

Response — 201 Created​

{
"status": "success",
"phone_number": {
"phone_uuid": "e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63",
"phone_number": "+14155550100",
"label": "US support line",
"provider": "twilio",
"agents": [],
"is_linked": false,
"capabilities": { "voice": true, "sms": true, "mms": true, "fax": false, "sms_enabled": true },
"sip_trunk_uuid": null,
"inbound_taken_elsewhere": false,
"inbound_taken_by": null
}
}

phone_number has the same shape as an item of List numbers. A new number is linked to no agent. Save phone_uuid: the other routes use it.

Before you retry

If a request times out, check List numbers before sending it again: the first request may still have added the number. A retry sent after the first request finished fails with 409 (This phone number is already added.), but one sent while the first is still running can add the number twice.


Delete a number​

DELETE /voice/phone_numbers/{phone_uuid}

Removes a number from your workspace permanently, as Delete does in the app. A sip number is also removed from its SIP trunk.

  • The number stays yours at the provider. DronaHQ doesn't release it, so you keep paying for it there until you release it yourself.
  • Unlink it first. Delete doesn't take the number out of the call settings of the agents linked to it. Unlink agents from a number does.
curl -X DELETE https://<your-dronahq-host>/voice/phone_numbers/e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63 \
-H "api-key: sk_your-generated-secret-here"

Response — 200 OK​

{
"status": "success",
"message": "Phone number deleted successfully",
"phone_uuid": "e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63",
"phone_number": "+14155550100"
}

A second delete of the same number returns 404.


POST /voice/phone_numbers/{phone_uuid}/link

Links the number to an agent, as picking it in the agent's Call Configuration does in the app. The number is added to the agent's inbound or outbound numbers; numbers already there stay.

  • Inbound: the agent answers calls to this number. A number answers inbound calls for one agent only, so a number another agent already answers on is refused with 409. To move it, unlink it from that agent and publish that agent: until then, its published version still answers on the number.
  • Outbound: the agent can call from this number. Several agents can call from the same number. The agent's default outbound number is the one a dispatch that sends no source_phone_number calls from. An agent's first outbound number becomes its default.
Publish to make it live

Linking changes the agent's draft. Inbound calls to the number reach the agent, and dispatch calls from its default number, only once the agent is published. The response's publish_state tells you whether it needs to be. To publish, send {"publish": true} to Update an agent. See Draft and published.

Body​

FieldTypeRequiredDescription
agent_uuidstringYesThe voice agent to link the number to
directionstringYesinbound or outbound. To use a number both ways, link it twice
is_defaultbooleanNoOutbound only: true makes this the agent's default outbound number. Default false, which leaves the agent's default where it is

An unknown field, a direction other than inbound or outbound, or is_default with inbound is rejected with 422.

Example request​

curl -X POST https://<your-dronahq-host>/voice/phone_numbers/e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63/link \
-H "api-key: sk_your-generated-secret-here" \
-H "Content-Type: application/json" \
-d '{ "agent_uuid": "3b7e1c2a-5d4f-4e8a-9b6c-0f1e2d3c4b5a", "direction": "outbound", "is_default": true }'

Response — 200 OK​

{
"status": "success",
"message": "Phone number linked successfully",
"phone_uuid": "e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63",
"agent_uuid": "3b7e1c2a-5d4f-4e8a-9b6c-0f1e2d3c4b5a",
"direction": "outbound",
"changed": true,
"is_default": true,
"linked_agent_uuids": ["3b7e1c2a-5d4f-4e8a-9b6c-0f1e2d3c4b5a"],
"publish_state": "unpublished_changes"
}
FieldDescription
changedfalse when the number was already linked to the agent that way, so nothing was saved
is_defaultFor an outbound link, whether this is now the agent's default outbound number. null for an inbound link
linked_agent_uuidsThe agents the number is linked to now. Only agents the key can access are listed
publish_stateunpublished_changes: the draft differs from the published version, so publish to make the link live. not_published: the agent has never been published. up_to_date: the published version already has it. null if it couldn't be read; the link is saved either way

Linking is safe to repeat. A link that is already there changes nothing, and message says Phone number already linked.

When another agent already answers inbound calls on the number, the 409 says so. inbound_taken_by names that agent if the key can access it, and is null otherwise, or when the number answers in another workspace:

{
"detail": {
"message": "+14155550100 (already answering on “Order Helper”) is already receiving inbound calls. A number can only take inbound calls for one agent — free it up there first, or use it here for outbound only.",
"inbound_taken_by": "9d2f4a6b-8c1e-4b3d-a5f7-6e0c2b4d8a1f"
}
}

POST /voice/phone_numbers/{phone_uuid}/unlink

Takes the number away from agents, as Unlink does in the app. The number is also removed from each of those agents' call settings, inbound and outbound. The number itself stays in your workspace.

Body​

The body is optional.

FieldTypeDescription
agent_uuidsarray of stringsThe agents to unlink, at least one. An agent that isn't linked to the number is skipped. Leave the field out to unlink every agent the key can access: with All Agents, every agent the number is linked to

An unknown field, or an empty agent_uuids, is rejected with 422.

Example request​

curl -X POST https://<your-dronahq-host>/voice/phone_numbers/e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63/unlink \
-H "api-key: sk_your-generated-secret-here" \
-H "Content-Type: application/json" \
-d '{ "agent_uuids": ["3b7e1c2a-5d4f-4e8a-9b6c-0f1e2d3c4b5a"] }'

Response — 200 OK​

{
"status": "success",
"message": "Phone number unlinked successfully",
"phone_uuid": "e5b0c2d4-6a1f-4c3e-9b7d-2f8a1c0e4d63",
"unlinked_agent_uuids": ["3b7e1c2a-5d4f-4e8a-9b6c-0f1e2d3c4b5a"],
"linked_agent_uuids": []
}
FieldDescription
unlinked_agent_uuidsThe agents this request unlinked
linked_agent_uuidsThe agents still linked to the number. Only agents the key can access are listed

Unlinking is safe to repeat. When there is nothing to unlink, the request still succeeds, unlinked_agent_uuids is empty, and message says why: Phone number is already unlinked, or Phone number is not linked to the requested agent(s).


Errors​

Error shapes​

Every error has a detail field, but its shape depends on the error:

detail isWhen
A string, for example "Phone number not found."401 and 403 from the key or its Agent Access, and 404 for a number or, on link, an agent
An object with a messageA number or credentials the provider refused (400), a SIP trunk that wasn't found (404), a number that is already added (409), a number another agent answers on (409 on link, with inbound_taken_by), and 500
An array of errorsA body that fails validation (422): an unknown field, a missing provider or phone_number, a value that isn't a string in auth_config, a field over its length limit, an empty agent_uuids, or on link a missing agent_uuid, a wrong direction, or is_default with inbound
{ "detail": { "status": "error", "message": "This phone number is already added." } }
{ "detail": [ { "type": "extra_forbidden", "loc": ["body", "phone"], "msg": "Extra inputs are not permitted", "input": "+14155550100" } ] }

Status codes​

HTTP statusCauseFix
400Add only: the provider isn't supported, phone_number isn't E.164, the credentials are missing (a sip_trunk_uuid for sip), or the provider refused the credentials or the number. detail.message says whichFix the field the message names. Check the credentials in the provider's console
401The key is missing, unknown, disabled or expiredCheck the key under Developer → API Keys: it must be enabled and not expired
403The key lacks the Phone numbers scopeAdd Phone numbers to the key
403The key's Agent Access doesn't reach the number, or the delete, link or unlink touches agents outside itSee Keys limited to some agents
404No number with this phone_uuid in the key's workspace, or the phone_uuid isn't a valid UUID. On add: the sip_trunk_uuid isn't a SIP trunk in your workspace. On link: agent_uuid isn't a voice agent in your workspaceCheck the id with List numbers, or the agent with List agents. A number in another workspace is a 404 too
409Add: the number is already in your workspaceNothing to do: it was added. Find it with List numbers
409Link: another agent already answers inbound calls on the numberUnlink it from that agent and publish that agent, or link it here as outbound
422The body is invalidRead detail
500Unexpected server error. detail.message names the action, for example Could not add the phone number.Retry; contact support if it persists

What's Next​