API Reference

OverviewSMSSMS batch APIVoice CallingVoice MessagingConversations APIContacts API (v2)Integrations APIFile Storage APIOmnichannel WidgetNumbersPartner AccountsVerifyMMSHLRBalanceLookupContactsGroupsIntentFAQNamed Entity RecognitionLanguage Detection

Voice Calling API

Messagebird’s Voice Calling API enables VoIP features for your web application to make, receive, and monitor voice calls from a MessageBird voice-enabled virtual mobile number to and from any country around the world through a REST API.

The Voice Calling API uses HTTP verbs and a RESTful endpoint structure with an access key that is used as the API Authorization. Request and response payloads are formatted as JSON using UTF-8 encoding and URL encoded values.

Looking for a VoIP tool but not a developer? Check out SIP Trunking on your MessageBird Dashboard.

If you are looking for specific documentation for a step you can directly jump to callflow step documentation.


Requests

API Endpoint

All URLs referenced in MessageBird's Voice Calling API documentation have the base URL in the code snippet on the right side:

https://voice.messagebird.com

Available HTTP methods

The MessageBird API uses HTTP verbs to understand if you want to read (GET), delete (DELETE), create (POST) or update (PUT) an object. When your web application cannot do a PUT, POST or DELETE, we provide the ability to set the method through the query parameter _method.

GET /call-flows/
POST /call-flows/
GET /call-flows/{id}
PUT /call-flows/{id}
DELETE /call-flows/{id}
GET /call-flows/{id}/numbers
POST /call-flows/{id}/numbers
PUT /call-flows/{id}/numbers
POST /calls/
GET /calls/
GET /calls/{callID}
PUT /calls/{callID}
DELETE /calls/{callID}
POST /calls/{callID}/{destination}
GET /calls/{callID}/legs
GET /calls/{callID}/legs/{legID}
DELETE /legs/{legID}
POST /legs/{legID}/hold
POST /legs/{legID}/unhold
GET /calls/{callID}/legs/{legID}/recordings
GET /recordings/{recordingID}
GET /recordings/{recordingID}.wav
# DEPRECATED:
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}.wav
GET /recordings/{recordingID}/transcriptions
POST /recordings/{recordingID}/transcriptions
GET /transcriptions/{transcriptionID}
GET /transcriptions/{transcriptionID}.txt
# DEPRECATED:
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions/{transcriptionID}
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions/{transcriptionID}.txt
POST /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions
GET /webhooks/
GET /webhooks/{id}
POST /webhooks/
PUT /webhooks/{id}
DELETE /webhooks/{id}

POST/PUT

POST and PUT requests to the API should contain a JSON-formatted payload in the request body.

JSON Request Payload Example

{
"steps": [
{
"id": "foo",
"action": "transfer",
"options": {
"destination": "31612345678"
}
},
{
"id": "bar",
"action": "hangup"
}
]
}

Voice Calling API authentication

MessageBird's Voice Calling API uses API keys to authenticate requests. You can view and manage your API keys in your MessageBird dashboard

Test API keys have the prefix test_ and live API keys have the prefix live_

With each API call, you will need to set request headers including your access key to authenticate yourself.

HeaderDescriptionRequired
AuthorizationMust be in the form of AccessKey {accessKey}.Yes

Errors

Codes in the 2xx range indicate that a request was successfully processed and codes in the 4xx range indicate that there was an error that resulted from the information sent (e.g. authentication, no balance or a missing or wrong parameter).

In case of an error, the body of the response includes a json formatted response that tells you exactly what is wrong.

Attributes

AttributeTypeDescription
errors[].codeintegerAn integer that represents the error type.
errors[].descriptionstringA human-readable description of the error. You can provide your users with this information to indicate what they can do about the error.

Error Object Example

{
"errors": [
{
"description": "The 'steps' parameter is required.",
"code": 11
}
]
}

Limits

POST and PUT requests to the API should contain a JSON-formatted payload of less than 64KB in the request body.

HTTP status codes

MessageBird uses standard HTTP status codes to indicate success or failure of an API request.

HTTP status codeDescription
200 FoundThe requested resource was found.
201 CreatedA resource has been created.
204 No ContentThe requested resource is empty.
400 Bad RequestThe request contains invalid/missing data, or is malformed.
401 UnauthorizedThe access key is missing or incorrect.
403 ForbiddenAccess to the requested resource was forbidden.
404 Not FoundThe resource could not be found.
405 Method Not AllowedThe HTTP method is not allowed.
409 ConflictRequest conflict with the current state of the server.
500 Internal Server ErrorSomething went wrong on our end, please try again.

Error codes (deprecated)

The following error codes have been deprecated in favor of relying on the status codes listed above.

CodeDescription
11A required parameter is missing in the request.
12A parameter has an invalid value.
13The requested resource could not be found.
14Access to the requested resource was forbidden.
15Authentication is missing from the HTTP request.
16The request body could not be parsed. Check if the body contents correspond with the supplied Content-Type HTTP header.
18A query parameter has an invalid value.
21An internal server error on the MessageBird platform occured.
25A requested action on the object can't be processed.

Call flows

A call flow describes the flow of operations (steps) to be executed when handling an incoming call. Call flows can be assigned to multiple numbers. A number in this context is a purchased number that can be called on the traditional phone network. Each object in the steps array in a call flow describes an operation that executes during a call, e.g. transferring a call or playing back an audio file. The call flow must not exceed 32KB.

URI

https://voice.messagebird.com/call-flows

Available HTTP Methods

GET /call-flows/
POST /call-flows/
GET /call-flows/{id}
PUT /call-flows/{id}
DELETE /call-flows/{id}
GET /call-flows/{id}/numbers
POST /call-flows/{id}/numbers
PUT /call-flows/{id}/numbers

The call flow object

This is an object representing a voice call flow at MessageBird.com.

Attributes

AttributeTypeDescription
idstringThe unique ID of the call flow.
recordboolSays whether a full call recording is enabled on this call flow, the default value for this attribute is false.
stepsarrayAn array of step objects. The sequence of the array items describe the order of execution, where the first item will be executed first, than the second, etcetera. See steps
defaultboolThe default attribute says whether the call flow will be used when no call flow was found for an inbound number. Only one default call flow is allowed.
createdAtdatetimeThe date-time the call flow was created, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
updatedAtdatetimeThe date-time the call flow was last updated, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).

Call Flow Object Example

{
"id": "de3ed163-d5fc-45f4-b8c4-7eea7458c635",
"record": true,
"steps": [
{
"id": "3538a6b8-5a2e-4537-8745-f72def6bd393",
"action": "transfer",
"options": {
"destination": "31612345678"
},
}
],
"createdAt": "2017-03-06T13:34:14Z",
"updatedAt": "2017-03-06T13:34:14Z"
}

List all call flows

This request retrieves a listing of all call flows.

Response

If successful, this request will return an object with a data, _links and pagination properties.

If the request failed, an error object will be returned.

The data property is an array of call flow objects, can be null if there are no call flows. The _links property is an object with HATEOAS links related to the object listing. The pagination property is an object with details about the result page count, total count, and pagination numbers.

Definition

GET https://voice.messagebird.com/call-flows

Example request

curl -X GET "https://voice.messagebird.com/call-flows" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "de3ed163-d5fc-45f4-b8c4-7eea7458c635",
"record": false,
"steps": [
{
"id": "3538a6b8-5a2e-4537-8745-f72def6bd393",
"action": "transfer",
"options": {
"destination": "31612345678"
}
}
],
"createdAt": "2017-03-06T13:34:14Z",
"updatedAt": "2017-03-06T13:34:14Z",
"_links": {
"self": "/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635"
}
}
],
"_links": {
"self": "/call-flows?page=1"
},
"pagination": {
"totalCount": 1,
"pageCount": 1,
"currentPage": 1,
"perPage": 10
}
}

Viewing a call flow

This request retrieves a call flow resource.

The single parameter is the unique ID that was returned upon creation.

Required parameters
ParameterTypeDescription
idstringThe unique ID which was returned upon creation of a call flow.

Response

If successful, this request will return an object with a data property, which is an array that has a single call flow object. If the request failed, an error object will be returned.

Definition

GET https://voice.messagebird.com/call-flows/{callflowID}

Example request

curl -X GET https://voice.messagebird.com/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635 \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "de3ed163-d5fc-45f4-b8c4-7eea7458c635",
"record": false,
"steps": [
{
"id": "3538a6b8-5a2e-4537-8745-f72def6bd393",
"action": "transfer",
"options": {
"destination": "31611223344"
}
}
],
"createdAt": "2017-03-06T13:34:14Z",
"updatedAt": "2017-03-06T15:02:38Z",
}
],
"_links": {
"self": "/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635"
}
}

Creating a call flow

Using JSON

Callflow parameters

AttributeTypeDescriptionRequired
stepsarrayAn array of step objects.Yes
defaultboolThe default attribute says whether the call flow will be used when no call flow found for inbound number. Only one default call flow is allowed and the default value for this attribute is false.No
recordboolInforms if a full call recording should be performed. If this option is set to true the call will be recorded, the default is false.No

Response

If successful, this request will return an object with a data property, which is an array that has a single call flow object. If the request failed, an error object will be returned.

Definition

POST https://voice.messagebird.com/call-flows

Example request

curl -X POST https://voice.messagebird.com/call-flows \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-H "Content-Type: application/json" \
-d $'{
"record": true,
"steps": [
{
"options": {
"destination": "31612345678"
},
"action": "transfer"
}
]
}'

Example response

{
"data": [
{
"id": "de3ed163-d5fc-45f4-b8c4-7eea7458c635",
"record": true,
"steps": [
{
"id": "2fa1383e-6f21-4e6f-8c36-0920c3d0730b",
"action": "transfer",
"options": {
"destination": "31612345678"
}
}
],
"createdAt": "2017-03-06T14:52:22Z",
"updatedAt": "2017-03-06T14:52:22Z"
}
],
"_links": {
"self": "/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635"
}
}

Steps

Each step object describes an action that can be taken in a call flow and holds the parameters for that action.

If you are looking for specific documentation for a step you can directly use the links below:

The say step

The say step pronounces a text message with a given voice and language.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be say to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
onKeypressVarstringThe name of the variable used for storing a keypress value when a key is pressed during this step. Setting this will trigger a default timeout of 3 seconds after the sound is played waiting for a keypress. Variables can be used with conditionals.
onKeypressGotostringThe ID of the step to jump to when the caller presses a key during this step. If maxNumKeys the jump will happen only after reaching this number or timeout is reached.
endKeystringIf set, determines which DTMF can trigger the next step (before the maxNumKeys or timeout is reached). The end key is not included in the resulting variable.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
payloadstringThe text to pronounce. Max length 3000 symbolsYes
languagestringThe language of the text that is to be pronounced. For a list of allowed values see supported languagesYes
voicestringThe preferred voice to use for pronouncing text. Allowed values: "male", "female". This preference is ignored if the desired voice is not available for the selected language. See also supported languagesYes
repeatintegerThe amount of times to repeat the payload. Allowed values: Between 1 and 10.No
timeoutintThe number of seconds to wait after the say step has finished for any keypress. Only taken into account if either onKeypressVar or onKeypressGoto are set. Default value is 3No
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check, just play the message; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
loopboolIf set to true the say step will be repeated indefinitely or until another step is executed when used in combination with the onKeypressGoto parameter.No
enginestringIf set, specifies the Text to Speech (TTS) engine that will be used to say the message. Possible TTS engines include google, amazon or microsoft. Not all language and voice combinations are possible for each provider; for details consult the list of supported languages by engine.No
{
"steps": [
{
"action": "say",
"options": {
"payload": "Hello, I am a robot. This is an example message.",
"language": "en-GB",
"voice": "male",
"repeat": 2
},
"onKeypressGoto": "bar",
"onKeypressVar": "foo"
}
]
}

Supported languages

The table below contains a list of locales with the options for the voice attribute of the say step. M denotes male and F female.

LocaleDescriptionVoices
af-ZAAfrikaans (South Africa)M, F
ar-EGArabic (Egypt)M, F
ar-SAArabic (Saudi Arabia)M, F
ar-XAArabicM, F
bg-BGBulgarian (Bulgaria)M, F
bn-INBangla (India)M, F
ca-ESCatalan (Spain)M, F
cmn-CNChinese (China)M, F
cmn-TWChinese (Taiwan)M, F
cs-CZCzech (Czechia)M, F
cy-GBWelsh (United Kingdom)M, F
da-DKDanish (Denmark)M, F
de-ATAustrian GermanM, F
de-CHSwiss High GermanM, F
de-DEGerman (Germany)M, F
el-GRGreek (Greece)M, F
en-AUAustralian EnglishM, F
en-CACanadian EnglishM, F
en-GBBritish EnglishM, F
en-GB-WLSBritish EnglishM
en-IEEnglish (Ireland)M, F
en-INEnglish (India)M, F
en-USAmerican EnglishM, F
es-ESEuropean SpanishM, F
es-MXMexican SpanishM, F
es-USSpanish (United States)M, F
fi-FIFinnish (Finland)M, F
fil-PHFilipino (Philippines)M, F
fr-CACanadian FrenchM, F
fr-CHSwiss FrenchM, F
fr-FRFrench (France)M, F
gu-INGujarati (India)M, F
he-ILHebrew (Israel)M, F
hi-INHindi (India)M, F
hr-HRCroatian (Croatia)M, F
hu-HUHungarian (Hungary)M, F
id-IDIndonesian (Indonesia)M, F
is-ISIcelandic (Iceland)M, F
it-ITItalian (Italy)M, F
ja-JPJapanese (Japan)M, F
jv-IDJavanese (Indonesia)M, F
kn-INKannada (India)M, F
ko-KRKorean (South Korea)M, F
lv-LVLatvian (Latvia)M, F
ml-INMalayalam (India)M, F
ms-MYMalay (Malaysia)M, F
nb-NONorwegian Bokmål (Norway)M, F
nl-BEFlemishM, F
nl-NLDutch (Netherlands)M, F
pa-INPunjabi (India)M, F
pl-PLPolish (Poland)M, F
pt-BRBrazilian PortugueseM, F
pt-PTEuropean PortugueseM, F
ro-RORomanian (Romania)M, F
ru-RURussian (Russia)M, F
sk-SKSlovak (Slovakia)M, F
sl-SISlovenian (Slovenia)M, F
sr-RSSerbian (Serbia)M, F
sv-SESwedish (Sweden)M, F
ta-INTamil (India)M, F
te-INTelugu (India)M, F
th-THThai (Thailand)M, F
tr-TRTurkish (Turkey)M, F
uk-UAUkrainian (Ukraine)M, F
vi-VNVietnamese (Vietnam)M, F
yue-HKCantonese (Hong Kong SAR China)M, F
zh-CNChinese (China)M, F
zh-HKChinese (Hong Kong SAR China)M, F
zh-TWChinese (Taiwan)M, F
Notification icon

If a voice provider is temporarily unavailable and it is necessary, we will automatically choose another text-to-speech engine to pronounce the provided text. This could temporarily change the type of voice and character of the pronunciation.

Supported languages by Engine

Not all text to speech engines provide the same combinations of languages and voices. By default we will automatically select an engine if one is not specified, or will fall back to a suitable engine if the one provided in the Say step does not have the appropriate language & voice combination. Before selecting a different engine, a different voice will be attempted first when the engine option is specified.

LocaleDescriptionAmazonMicrosoftGoogle
af-ZAAfrikaans (South Africa)-M, FF
ar-EGArabic (Egypt)-M, F-
ar-SAArabic (Saudi Arabia)-M, F-
ar-XAArabic--M, F
bg-BGBulgarian (Bulgaria)-M, FF
bn-INBangla (India)-M, FM, F
ca-ESCatalan (Spain)-M, FF
cmn-CNChinese (China)F-M, F
cmn-TWChinese (Taiwan)--M, F
cs-CZCzech (Czechia)-M, FF
cy-GBWelsh (United Kingdom)FM, F-
da-DKDanish (Denmark)M, FM, FM, F
de-ATAustrian German-M, F-
de-CHSwiss High German-M, F-
de-DEGerman (Germany)M, FM, FM, F
el-GRGreek (Greece)-M, FF
en-AUAustralian EnglishM, FM, FM, F
en-CACanadian English-M, F-
en-GBBritish EnglishM, FM, FM, F
en-GB-WLSBritish EnglishM--
en-IEEnglish (Ireland)-M, F-
en-INEnglish (India)FM, FM, F
en-USAmerican EnglishM, FM, FM, F
es-ESEuropean SpanishM, FM, FM, F
es-MXMexican SpanishFM, F-
es-USSpanish (United States)M, FM, FM, F
fi-FIFinnish (Finland)-M, FF
fil-PHFilipino (Philippines)-M, FM, F
fr-CACanadian FrenchFM, FM, F
fr-CHSwiss French-M, F-
fr-FRFrench (France)M, FM, FM, F
gu-INGujarati (India)-M, FM, F
he-ILHebrew (Israel)-M, F-
hi-INHindi (India)FM, FM, F
hr-HRCroatian (Croatia)-M, F-
hu-HUHungarian (Hungary)-M, FF
id-IDIndonesian (Indonesia)-M, FM, F
is-ISIcelandic (Iceland)M, FM, FF
it-ITItalian (Italy)M, FM, FM, F
ja-JPJapanese (Japan)M, FM, FM, F
jv-IDJavanese (Indonesia)-M, F-
kn-INKannada (India)-M, FM, F
ko-KRKorean (South Korea)FM, FM, F
lv-LVLatvian (Latvia)-M, FM
ml-INMalayalam (India)-M, FM, F
ms-MYMalay (Malaysia)-M, FM, F
nb-NONorwegian Bokmål (Norway)FM, FM, F
nl-BEFlemish-M, FM, F
nl-NLDutch (Netherlands)M, FM, FM, F
pa-INPunjabi (India)--M, F
pl-PLPolish (Poland)M, FM, FM, F
pt-BRBrazilian PortugueseM, FM, FF
pt-PTEuropean PortugueseM, FM, FM, F
ro-RORomanian (Romania)FM, FF
ru-RURussian (Russia)M, FM, FM, F
sk-SKSlovak (Slovakia)-M, FF
sl-SISlovenian (Slovenia)-M, F-
sr-RSSerbian (Serbia)-M, FF
sv-SESwedish (Sweden)FM, FF
ta-INTamil (India)-M, FM, F
te-INTelugu (India)-M, FM, F
th-THThai (Thailand)-M, FF
tr-TRTurkish (Turkey)FM, FM, F
uk-UAUkrainian (Ukraine)-M, FF
vi-VNVietnamese (Vietnam)-M, FM, F
yue-HKCantonese (Hong Kong SAR China)--M, F
zh-CNChinese (China)-M, F-
zh-HKChinese (Hong Kong SAR China)-M, F-
zh-TWChinese (Taiwan)-M, F-

The record step

The record step initiates an audio recording during a call, e.g. for capturing a user response. The recording can be stopped by using one or more of the attributes maxLength, timeout, finishOnKey.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be record to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
onFinishstringA URL from which a new call flow is fetched after the recording stops. The request is a POST request and contains details of the recording.No
onFinishTimeoutintegerThe timeout in seconds for fetching the call flow from the onFinish URL. Allowed values: Between 1 and 30. For backwards compatibility it defaults to the timeout value if set and otherwise defaults to 5 seconds.No
timeoutintegerSeconds of silence allowed before the recording is automatically stopped. If you omit this parameter, silence detection is disabled. If set, it is advised to also explicitly set onFinishTimeout.No
maxLengthintegerMaximum length of the recording in seconds. The default is no limit on the recording length.No
finishOnKeystringKey DTMF input to stop the recording. Values allowed are "any", #, *, "none". The default is "none", which means that the recording will not be stopped by a DTMF.No
transcribeboolIf you want to have a transcription of the recording, after the recording has finished. Default value is false.No
transcribeLanguagestringThe language of the recording that is to be transcribed. Required when transcribe is true. Allowed values: "de-DE", "en-AU", "en-UK", "en-US", "es-ES", "es-LA", "fr-FR", "it-IT", "nl-NL", "pt-BR".No
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
beepboolWhether or not to play a beep when recording begins. Default is trueNo
{
"steps": [
{
"action": "record",
"options": {
"onFinish": "https://messagebird.com/onfinish",
"timeout": 10,
"maxLength": 30,
"finishOnKey": "any",
"transcribe": true,
"transcribeLanguage": "en-UK"
}
}
]
}

The transfer step

The transfer step transfers the call to a different phone/server. When used with the steps option listed below, the transfer will be completed to the destination only after finishing those steps. For more information on this option and how to use it, see our guide on Call Screening.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be transfer to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
destinationstringThe destination (E.164 formatted number, SIP URI or Client URI) to transfer a call to. E.g. 31612345678, sip:foobar@example.com, or client:name_of_client. The Client URI is in early access at this moment as part of our Client SDK.Yes
sourcestringSource to override the source for the transfer leg and mask the original source. For more details see Masking numbers. See allowed caller IDsNo
maskboolIf set to true the transfer call will appear to be coming from the destination of the primary leg effectively masking the original caller/source. If the source option of the transfer step is also set this value is ignored. For more details see Masking numbers.
recordstringUse this option if the transfer leg should be recorded. Option in is being used to record the voice of the destination and out for the source. You can use both to record both source and destination individually. Allowed values: in, out and both options.No
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
noAnswerTimeoutintegerRinging timeout for not answered call in seconds. Minimum: 20. Maximum: 90. Default: 30.No
maxDurationinteger or stringMaximum duration of the call in seconds or as a string. Can contain units of time: e.g. 50s/10m/2h. Minimum: "30s". Maximum: "8h". Default: "8h".No
stepsarrayArray of steps to execute after the transfer call is picked up but before connecting the parties. Applicable steps are limited to say, play, pause, and hangup. For more information consult these options and our guide on Call Screening.No
{
"steps": [
{
"action": "transfer",
"options": {
"destination": "31612345678",
"record": "both"
}
}
]
}

The maskedTransfer step

The maskedTransfer step is used on inbound flows to create a number-masking call. When one of the numbers in the numbers array option is matched to the calling party (source) the call is transferred to the other number in this array. However the Calling Line Identity will be replaced with the number that this flow is connected to. If there is no match no transfer will happen and the inbound call will fail. For more masking options see Masking numbers.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be maskedTransfer to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
numbersarrayAn array of strings, where each string is an E.164 formatted number (e.g. 31612345678).Yes
recordstringUse this option if the transfer leg should be recorded. Option in is being used to record the voice of the destination and out for the source. You can use both to record both source and destination individually. Allowed values: in, out and both options.No
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
noAnswerTimeoutintegerRinging timeout for not answered call in seconds. Minimum: 20. Maximum: 90. Default: 30.No
maxDurationinteger or stringMaximum duration of the call in seconds or as a string. Can contain units of time: e.g. 50s/10m/2h. Minimum: "30s". Maximum: "8h". Default: "8h".No
stepsarrayArray of steps to execute after the transfer call is picked up but before connecting the parties. Applicable steps are limited to say, play, pause, and hangup. For more information consult these options and our guide on Call Screening.No
{
"steps": [
{
"action": "maskedTransfer",
"options": {
"numbers": ["31612345678", "31612345679"]
}
}
]
}

Masking numbers

There are three ways to mask numbers for calls you place using the Voice API depending on your use case. In all scenarios two parties A and B would be able to talk to each other without knowing each other's numbers but using a Proxy Number from Messagebird denoted as N.

  1. maskedTransfer step
  2. transfer step with mask option
  3. transfer step with source option

maskedTransfer step

Use a maskedTransfer step in the callflow of an incoming call to recognize and link two parties together without exposing their numbers to each other. e.g. If N is a Proxy number you own and A and B are numbers that should talk to each other but remain anonymous you could achieve it by letting them both call number N, and setting the callflow of N to be the following:

{
"steps": [
{
"action": "maskedTransfer",
"options": {
"numbers": ["A", "B"]
}
}
]
}

In that example if A calls N then B will receive the transferred call as coming from N. Equally, if B calls N then A would receive the call as coming from N.

transfer step with mask option

Set the mask option to true for a transfer step when you want any incoming call to be forwarded to the transfer destination appearing to come from the same number that they originally dialed-in. e.g. If N is a Proxy number you own and A called N you can transfer the call to B with both sides being anonymous by setting the callflow of N to be the following:

{
"steps": [
{
"action": "transfer",
"options":{
"destination": "B"
}
}
]
}

This option is similar to the maskedTransfer above but behaves the same without requiring the caller's number in the callflow. Note that this convenience method does not work well for calls originated by the API but only incoming calls.

transfer step with source option

Set the source option for a transfer step when you want to have full control over how the transfer leg appears to the transfer destination. This is the suggested way when placing a call to party A and then transferring them to party B but requiring anonymity of the two parties. e.g. In the following example A is receiving a call from N and then gets transferred to B. B will see the caller of the transfer leg being C (you may also opt for reusing the number N as C).

{
"destination": "A",
"source": "N",
"steps": [
{
"action": "transfer",
"options":{
"destination": "B",
"source": "C"
}
}
]
}

The hangup step

The hangup step ends the call.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be hangup to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
conditionsarraySee conditionals
{
"steps": [
{
"action": "hangup"
}
]
}

The fetchCallFlow step

The fetchCallFlow step fetches a new call flow from the supplied URL and transfers control to that flow, see Dynamic call flows.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be fetchCallFlow to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
urlstringThe URL to fetch the new call flow from.Yes
timeoutintegerThe timeout in seconds for fetching the call flow from the url. Allowed values: Between 1 and 30. Defaults to 5.No
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
tokenstringToken that will be used to sign the request to the supplied URL in order to verify it is coming from MessageBird. See Validation of signaturesNo
{
"steps": [
{
"action": "fetchCallFlow",
"options": {
"url": "https://messagebird.com/fetchcallflow",
"timeout": 30
}
}
]
}

The play step

The play step plays back an audio file.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be play to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
onKeypressVarstringThe name of the variable used for storing a keypress value when a key is pressed during this step. Setting this will trigger a default timeout of 3 seconds after the sound is played waiting for a keypress. Variables can be used with conditionals.
onKeypressGotostringThe ID of the step to jump to when the caller presses a key during this step. If maxNumKeys the jump will happen only after reaching this number or timeout is reached.
endKeystringIf set, determines which DTMF can trigger the next step (before the maxNumKeys or timeout is reached). The end key is not included in the resulting variable.
maxNumKeysintegerAn optional limit to the number of DTMF events that should be gathered before continuing to the next step. By default, this is set to 1, so any key will trigger the next step. If EndKey is set and MaxNumKeys is unset, no limit for the number of keys that will be gathered will be imposed. It is possible for less keys to be gathered if the EndKey is pressed or the timeout being reached.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
mediastringThe URL of the media file to play. See Supported Media Types for a full list of audio files Messagebird supports. Note that the file extension can also be part of the last query parameter, so http://www.example.com/test.mp3?foo=bar&format=.mp3 is a valid format.Yes
loopboolIf set to true the say step will be repeated indefinitely or until another step is executed when used in combination with the onKeypressGoto parameter.No
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check, just play the media; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
timeoutintThe number of seconds to wait after the play step has finished for any keypress. Only taken into account if either onKeypressVar or onKeypressGoto are set. Default value is 3No
{
"steps": [
{
"action": "play",
"options": {
"media": "https://messagebird.com/play.wav"
},
"onKeypressGoto": "bar",
"onKeypressVar": "foo"
}
]
}
Supported Media Types

Messagebird supports media types with the following file extensions .wav, .mp3, .g722, .gsm, .alaw, .al, .pcm, .ulaw, .raw, .sln, .sln12, .sln16, .sln24, .sln32, .sln44, .sln48, .sln96, .sln192, .vox.

Play Step Media Caching

By default, the audio file provided in the media is cached on Messagebird's media server before being played for the user. We do this in order to ensure that the audio file is played more quickly for your users and will result in higher resilience when playing audio in the event that the source file's media server experiences latency or downtime. Messagebird's media server has a cache retention period of 7 days, however we will respect the caching policy as dictated by the source file. To make the most of (or override) Messagebird's caching, note that we preserve the following headers for the media file: Cache-Control, Max-Age, Etag, and Last-Modified.

The pause step

The pause step pauses (silently) for a given duration.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be pause to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
onKeypressVarstringThe name of the variable used for storing a keypress value when a key is pressed during this step. Variables can be used with conditionals.
onKeypressGotostringThe ID of the step to jump to when the caller presses a key during this step.
endKeystringIf set, determines which DTMF can trigger the next step (before the maxNumKeys or timeout is reached). The end key is not included in the resulting variable.
maxNumKeysintegerAn optional limit to the number of DTMF events that should be gathered before continuing to the next step. By default, this is set to 1, so any key will trigger the next step. If EndKey is set and MaxNumKeys is unset, no limit for the number of keys that will be gathered will be imposed. It is possible for less keys to be gathered if the EndKey is pressed or the timeout being reached.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
lengthinteger or stringThe length of the pause. If an integer is given, the pause duration will be in seconds. When providing a string, the unit must be specified. Supported units include us, ms and s. Acceptable pause durations are between 0 - 59s.Yes
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
{
"steps": [
{
"action": "pause",
"options": {
"length": "2s"
},
"onKeypressGoto": "bar",
"onKeypressVar": "foo"
}
]
}

The sendKeys step

The sendKeys step sends DTMF signals during a call.

Parameters

AttributeTypeDescription
idstringThe unique (within the call flow) identifier of the step.
actionstringMust be sendKeys to perform this action
optionsobjectContains zero or more key-value pairs, where the key is the identifier of the option and value is the option value. See below.
conditionsarraySee conditionals

Options object

AttributeTypeDescriptionRequired
keysstringKeys to send. Allowed set of characters: 0-9, A-D, #, *; with a maximum of 100 keys.Yes
durationintegerDuration of DTMF tone per key in milliseconds. Allowed values: Between 100 and 1000.No
intervalintegerInterval between sending keys in milliseconds. Allowed values: Between 0 and 5000.No
ifMachinestringAction to do when a machine picks up the phone. Possible values are: "continue" - do not check; "delay" if a machine answers, wait until the machine stops talking; "hangup" hangup when a machine answers. See AMDNo
machineTimeoutintegerThe time (in milliseconds) to analyze if a machine has picked up the phone. Used in combination with the "delay" and "hangup" values of the "ifMachine" attribute. Minimum: 400, maximum: 10000. Default: 7000.No
{
"steps": [
{
"action": "sendKeys",
"options": {
"keys": "*101#",
"duration": 500,
"interval": 2000
}
}
]
}

Using XML

Besides JSON, you can also create an XML based call flow. They offer the same features as JSON, but can be more readable, especially when using step conditions.

To use XML when creating a call flow, the Content-Type HTTP header needs to be set to application/xml. Upon creation, an XML call flow is parsed into a flat array of steps. Any conditional structures with If are ket intact.

By default, steps are sequentially executed. Using the onKeypressGoto attribute in tags, you can alter flow control by skipping to a specific part of the call flow.

Notification icon

XML Element tags and attributes are case-sensitive. For example, using <play> instead of <Play> will give an error.

Example request

curl -X POST https://voice.messagebird.com/call-flows \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-H "Content-Type: application/xml" \
-d $'<?xml version="1.0" encoding="UTF-8"?>
<CallFlow>
<Say language="en-US" voice="male" onKeypressVar="foo" onKeypressGoto="bar">Hello! Press 1, 2, or 3 to continue.</Say>
<Pause length="10s" onKeypressVar="foo" onKeypressGoto="bar"/>
<Say language="en-US" voice="male">You did not press anything. Good bye!</Say>
<Hangup/>
<If id="bar" condition="foo == 1">
<Say language="en-US" voice="male">You pressed 1. Bye!</Say>
<Hangup/>
</If>
<If condition="foo == 2">
<Say language="en-US" voice="male">You pressed 2. Bye!</Say>
<Hangup/>
</If>
<If condition="foo == 3">
<Say language="en-US" voice="male">You pressed 3. Bye!</Say>
<Hangup/>
</If>
<Say language="en-US" voice="male">You pressed something, but it was not 1, 2 or 3. Bye!</Say>
</CallFlow>'

Example response

{
"data": [
{
"id": "9e568623-a158-45f5-aa71-d877349abafc",
"record": false,
"steps": [
{
"id": "800a9655-92b0-4f80-bdf7-63d5c7650ec6",
"action": "say",
"options": {
"payload": "Hello! Press 1, 2, or 3 to continue.",
"language": "en-US",
"voice": "male"
},
"onKeypressGoto": "bar",
"onKeypressVar": "foo"
},
{
"id": "71090bab-0683-438b-af57-490d7cdb94c8",
"action": "pause",
"options": {
"length": "10s"
},
"onKeypressGoto": "bar",
"onKeypressVar": "foo"
},
{
"id": "184019d3-5f58-4e7a-a770-cd1401440367",
"action": "say",
"options": {
"payload": "You didn't press anything. Good bye!",
"language": "en-US",
"voice": "male"
}
},
{
"id": "3b903119-821e-4e4f-baa3-83beb898f427",
"action": "hangup"
},
{
"id": "bar",
"action": "say",
"options": {
"payload": "You pressed 1. Bye!",
"language": "en-US",
"voice": "male"
},
"conditions": [
{
"variable": "foo",
"operator": "==",
"value": "1"
}
]
},
{
"id": "8570f016-c27c-44c1-9327-236df34684d3",
"action": "hangup",
"conditions": [
{
"variable": "foo",
"operator": "==",
"value": "1"
}
]
},
{
"id": "a5fadcfd-1c2a-4017-9e5a-72c5e4df8007",
"action": "say",
"options": {
"payload": "You pressed 2. Bye!",
"language": "en-US",
"voice": "male"
},
"conditions": [
{
"variable": "foo",
"operator": "==",
"value": "2"
}
]
},
{
"id": "a144f0e6-3702-4990-a63e-27d497ef801b",
"action": "hangup",
"conditions": [
{
"variable": "foo",
"operator": "==",
"value": "2"
}
]
},
{
"id": "4c6f803b-2e2f-458d-94a6-6698d53b0cc7",
"action": "say",
"options": {
"payload": "You pressed 3. Bye!",
"language": "en-US",
"voice": "male"
},
"conditions": [
{
"variable": "foo",
"operator": "==",
"value": "3"
}
]
},
{
"id": "a9bbba8b-ed1b-4fa4-bdae-85c668723103",
"action": "hangup",
"conditions": [
{
"variable": "foo",
"operator": "==",
"value": "3"
}
]
},
{
"id": "38eb5a4c-3a2a-4475-a056-e8ece4e57e17",
"action": "say",
"options": {
"payload": "You pressed something, but it wasn't 1, 2 or 3. Bye!",
"language": "en-US",
"voice": "male"
}
}
],
"createdAt": "2017-03-13T13:39:52Z",
"updatedAt": "2017-03-13T13:39:52Z"
}
],
"_links": {
"self": "/v1/call-flows/9e568623-a158-45f5-aa71-d877349abafc"
}
}

The Transfer tag

The Transfer tag transfers the call to a different phone/server. The Transfer tag may be optionally used as a container for other tags (steps) that are executed for the destination number before the transfer is complete. Applicable tags for such flows include the Play, Say, Hangup, Pause and If tags. For more information on this functionality, please see our guide on Call Screening.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the step.No
destinationstringThe destination (E.164 formatted number, SIP URI or Client URI) to transfer a call to. E.g. 31612345678, sip:foobar@example.com, or client:name_of_client. The Client URI is in early access at this moment as part of our Client SDK.Yes

The Say tag

The Say tag pronounces a text message with a given voice and language. The XML tag content should contain the text to pronounce. The maximum amount of characters for the payload is 3000.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the step.No
languagestringThe language of the text that is to be pronounced. For a list of allowed values see supported languagesYes
voicestringThe voice to use for pronouncing text. Allowed values: male, female. Note that if the selected voice is not available in the target language, Messagebird will fall back to using the alternate available voice.Yes
repeatintegerThe amount of times to repeat the payload.No
onKeypressVarstringThe name of the variable used for storing a keypress value when a key is pressed during this step. Variables can be used in If conditions.No
onKeypressGotostringThe ID of the step to jump to when the caller presses a key during this step.No
endKeystringIf set, determines which DTMF triggers the next step. The end key is not included in the resulting variable. If not set, no key will trigger the next step.No
maxNumKeysintegerAn optional limit to the number of DTMF events that should be gathered before continuing to the next step. By default, this is set to 1, so any key will trigger the next step. If EndKey is set and MaxNumKeys is unset, no limit for the number of keys that will be gathered will be imposed. It is possible for less keys to be gathered if the EndKey is pressed or the timeout being reached.No
loopboolIf set to true the say step will be repeated indefinitely or until another step is executed when used in combination with the onKeypressGoto attribute.No
enginestringIf set, specifies the Text to Speech (TTS) engine that will be used to say the message. Possible TTS engines include google, amazon or microsoft. Not all language and voice combinations are possible for each provider; for details consult the list of supported languages by engine.No

The Play tag

The Play tag plays back an audio file. The tag should not contain any content, only attributes.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the step.No
mediastringThe URL of the media file to play. See Supported Media Types for a full list of audio files Messagebird supports. Note that the file extension can also be part of the last query parameter, so http://www.example.com/test.mp3?foo=bar&format=.mp3 is a valid format.Yes
onKeypressVarstringThe name of the variable used for storing a keypress value when a key is pressed during this step. Variables can be used in If conditions.No
onKeypressGotostringThe ID of the step to jump to when the caller presses a key during this step.No
endKeystringIf set, determines which DTMF triggers the next step. The end key is not included in the resulting variable. If not set, no key will trigger the next step.No
loopboolIf set to true the say step will be repeated indefinitely or until another step is executed when used in combination with the onKeypressGoto attribute.No

The Pause tag

The Pause tag pauses (silently) for a given duration. The tag should not contain any content, only attributes.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the step.No
lengthinteger or stringThe length of the pause. If an integer is given, the pause duration will be in seconds. When providing a string, the unit must be specified. Supported units include us, ms and s. Acceptable pause durations are between 0 - 59s.Yes
onKeypressVarstringThe name of the variable used for storing a keypress value when a key is pressed during this step. Variables can be used in If conditions.No
onKeypressGotostringThe ID of the step to jump to when the caller presses a key during this step.No
endKeystringIf set, determines which DTMF triggers the next step. The end key is not included in the resulting variable. If not set, no key will trigger the next step.No
maxNumKeysintegerAn optional limit to the number of DTMF events that should be gathered before continuing to the next step. By default, this is set to 1, so any key will trigger the next step. If EndKey is set and MaxNumKeys is unset, no limit for the number of keys that will be gathered will be imposed. It is possible for less keys to be gathered if the EndKey is pressed or the timeout being reached.No

The Record tag

The Record tag initiates an audio recording during a call, e.g. for capturing a user response. The tag should not contain any content, only attributes. The recording can be stopped by using one or more of the attributes maxLength, timeout, finishOnKey.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the step.No
maxLengthintegerMaximum length of a recording in seconds. The default is no limit on the recording length.No
timeoutintegerThe amount in seconds of silence after which a recording should be stopped. Note that silence detection in noisy environments might not always provide the best results, so it is advised to also set a maxLength as fallback. The default is that silence detection is disabled.No
finishOnKeystringKey DTMF input to stop recording. Values allowed are any, #, *, none. The default is none, which means that a recording can not be stopped by a DTMF.No
transcribeboolSet to true if you want to have a transcription of the recording. The default is false.No
transcribeLanguagestringIf transcribe is set transcribeLanguage is required then. See transcribeLanguage for the list of available languages.No
beepboolWhether or not to play a beep when recording begins. Default is trueNo

Example

<CallFlow>
<Say language="en-US" voice="male">
Unfortunately we are not able to answer the phone right now. Please leave your name and number.
</Say>
<Record maxLength="120" timeout="3" transcribe="true" transcribeLanguage="en-US" />
<Say language="en-US" voice="male">
Thanks for calling, we will get back to you shortly.
</Say>
<Hangup/>
</CallFlow>

The SendKeys tag

The SendKeys tag sends the DTMF signals during a call.

It can be used to dial a number that is reachable via an extension number or to simulate the keypresses of a physical phone to walk through an IVR system.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the step.No
keysstringKeys to send. Allowed set of characters: 0-9, A-D, #, *; with a maximum of 100 keys.Yes

Example

curl -X POST https://voice.messagebird.com/calls \
-H "Content-Type: application/json" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-d $'{
"source": "31644556677",
"destination": "31626146604",
"callFlow": {
"steps": [{
"action": "sendKeys",
"options": {
"keys": "1234567890"
}
}]
},
"webhook": {
"url": "https://example.com",
"token": "foobar"
}
}'

The FetchCallFlow tag

The FetchCallFlow tag fetches a call flow from a remote URL. See: Dynamic call flows. Any steps following this tag are ignored. The tag should not contain any content, only attributes.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the step.No
urlstringThe URL to fetch a call flow from. Required when steps[].action is fetchCallFlow.Yes
timeoutintegerThe timeout for fetching the XML/JSON callflow from the URL the user specified at the fetchCallFlow action. It is optional with the default value being 5 seconds.No
tokenstringToken that will be used to sign the request to the supplied URL in order to verify it is coming from MessageBird. See Validation of signaturesNo

The Hangup tag

The Hangup tag ends the call. This is an empty-element tag that has no attributes.

The If tag

The If tag is a container where the contents are other tags (steps) that are executed when the condition in the condition attribute evaluates to true.

Parameters
AttributeTypeDescriptionRequired
idstringThe identifier of the If tag.No
conditionstringAn expression which will be evaluated before any nested steps are executed, e.g. foobar == 1. Variables need to be stored before the If tag is reached, by using the onKeypressVar in an earlier step. Valid operators are == and !=.Yes

Example

<CallFlow>
<Say language="en-US" voice="male" onKeypressVar="foo" onKeypressGoto="bar">Hello! Press 1, 2, or 3 to continue.</Say>
<Pause length="10s" onKeypressVar="foo" onKeypressGoto="bar"/>
<Say language="en-US" voice="male">You did not press anything. Good bye!</Say>
<Hangup/>
<If id="bar" condition="foo == 1">
<Say language="en-US" voice="male">You pressed 1. Bye!</Say>
<Hangup/>
</If>
<If condition="foo == 2">
<Say language="en-US" voice="male">You pressed 2. Bye!</Say>
<Hangup/>
</If>
<If condition="foo == 3">
<Say language="en-US" voice="male">You pressed 3. Bye!</Say>
<Hangup/>
</If>
<Say language="en-US" voice="male">You pressed something, but it wasn't 1, 2 or 3. Bye!</Say>
</CallFlow>

Updating a call flow

This request updates a call flow resource. The single parameter is the unique ID that was returned upon creation.

Required parameters
ParameterTypeDescriptionRequired
idstringThe unique ID which was returned upon creation of a call flow.Yes
Optional parameters
ParameterTypeDescriptionRequired
stepsarrayAn array of step objects that replaces the current array of steps.No
recordboolEnables or disables full call recording.No

Response

If successful, this request will return an object with a data property, which is an array that has a single call flow object. If the request failed, an error object will be returned.

Definition

PUT https://voice.messagebird.com/call-flows/{callflowID}

Example request

curl -X PUT https://voice.messagebird.com/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635 \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-d $'{
"steps": [
{
"options": {
"destination": "31611223344"
},
"action": "transfer"
}
]
}'

Example response

{
"data": [
{
"id": "de3ed163-d5fc-45f4-b8c4-7eea7458c635",
"record": false,
"steps": [
{
"id": "3538a6b8-5a2e-4537-8745-f72def6bd393",
"action": "transfer",
"options": {
"destination": "31611223344"
}
}
],
"createdAt": "2017-03-06T13:34:14Z",
"updatedAt": "2017-03-06T15:02:38Z"
}
],
"_links": {
"self": "/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635"
}
}

Deleting a call flow

This request deletes a call flow. The single parameter is the unique ID that was returned upon creation.

Required parameters
ParameterTypeDescriptionRequired
idstringThe unique ID which was returned upon creation of a call flow.Yes

Response

If successful, this request will return an HTTP header of 204 No Content and an empty response. If the request failed, an error object will be returned.

Definition

DELETE https://voice.messagebird.com/call-flows/{callflowID}

Example request

curl -X DELETE https://voice.messagebird.com/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635 \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'

Assigning numbers to a call flow

To use a call flow for incoming calls to your number(s), you'll need to assign these numbers to the callflow first. This can be accomplished either by adding (using method POST) or replacing (using method PUT) the numbers for the callflow. Apart from this the two endpoints will behave the same with the same request and responses.

Required parameters
ParameterTypeDescriptionRequired
idstringThe unique ID which was returned upon creation of a call flow.Yes
numbersarrayAn array of strings, where each string is an E.164 formatted number (e.g. 31612345678) you own.Yes

Response

If successful, this request will return an object with a data property, which is an array that has a single call flow object. If the request failed, an error object will be returned.

Definition

POST https://voice.messagebird.com/call-flows/{callflowID}/numbers
PUT https://voice.messagebird.com/call-flows/{callflowID}/numbers

Example request

# Add number to the call flow
curl -X POST https://voice.messagebird.com/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635/numbers \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-d $'{
"numbers": ["31611111111", "31622222222"]
}'
# Replace the numbers of the call flow
curl -X PUT https://voice.messagebird.com/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635/numbers \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-d $'{
"numbers": ["31611111111", "31622222222"]
}'

Listing numbers assigned to a call flow

This request retrieves a listing of all numbers currently assigned to a call flow.

Response

If successful, the request will return an object with a data, _links and pagination properties. If the request failed, an error object will be returned.

The data property is an array of number objects. The _links property is an object with HATEOAS links related to the object listing. The pagination property is an object with details about the result page count, total count, and pagination numbers.


Definition

GET https://voice.messagebird.com/call-flows/{callflowID}/numbers

Example request

curl -X GET "https://voice.messagebird.com/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635/numbers" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "13f38f34-7ff4-45b3-8783-8d5b1143f22b",
"number": "31611111111",
"callFlowId": "de3ed163-d5fc-45f4-b8c4-7eea7458c635",
"createdAt": "2017-03-16T13:49:24Z",
"updatedAt": "2017-09-12T08:59:50Z",
"_links": {
"self": "/numbers/13f38f34-7ff4-45b3-8783-8d5b1143f22b"
}
}
],
"_links": {
"self": "/call-flows/de3ed163-d5fc-45f4-b8c4-7eea7458c635/numbers?page=1"
},
"pagination": {
"totalCount": 1,
"pageCount": 1,
"currentPage": 1,
"perPage": 10
}
}

Answering Machine Detection (AMD)

Answering Machine Detection (AMD) allows you to determine whether the receiving side of an outgoing call is detected to be a machine (voicemail or fax). Depending on the outcome of the detection you can choose to either hangup the call (ifMachine: "hangup") or to wait until the answering machine has finished talking (ifMachine: "delay") before executing any further steps.

AMD on API originated calls

To enable AMD on the first leg of your callflow (for example a call with a simple callflow of a say step) you need to add an ifMachine attribute in the options of its first step. For available values see the callflow object.

{
"destination": "31612345678",
"source": "31644556677",
"callFlow": {
"steps": [
{
"action": "say",
"options": {
"payload": "Testing hangup on AMD for OTP. Call should hangup",
"voice": "male",
"language": "en-GB",
"ifMachine": "hangup"
}
}
]
},
"webhook": {
"url": "https://some-callback-url"
}
}

AMD on transfer steps

For transfers (where the primary leg is being connected to a secondary leg towards another number) the same options can be set directly as options of the transfer step. For available values see the callflow object.

{
"destination": "31612345678",
"source": "31644556677",
"callFlow": {
"steps": [
{
"action": "say",
"options": {
"payload": "Testing hangup on AMD for transfers. Call should hangup shortly after ringing.",
"voice": "male",
"language": "en-GB"
}
},
{
"action":"transfer",
"options":{
"destination":"31612345555",
"ifMachine":"hangup"
}
}
]
},
"webhook": {
"url": "https://some-callback-url"
}
}
Notification icon

If the first step of the callflow happens also to be a transfer step the directions will only have effect for the transfer step. If you wish to have AMD detection for the first leg you are advised to use an intermediate step to host the AMD options such as a short "Pause" step.

Notification icon

Answering Machine Detection doesn't come without side-effects. The algorithm works by detecting if the callee answered with an initial silence of a few seconds or started speaking for an unreasonable period without acknowledgement of the other party. Since the callflow will be delayed until a decision is made, especially for transfers that might mean that a part of the call might not be heard by both parties and could lead to some confusion.


AMD events in webhook callbacks

The outcome of the Answering Machine Detection is also sent as a separate event in callbacks. For more information read the callback section.

The AMDCompleteEvent

This is an object representing an AMDComplete event.

Attributes

AttributeTypeDescription
CallObjectThe Call object corresponding to the event. See: call.
LegObjectThe Leg object corresponding to the event. See: leg
StatusstringThe status of the AMD. Possible values: HUMAN, MACHINE, NOTSURE,HANGUP.
CausestringIndicates the cause that led to the conclusion. e.g. INITIALSILENCE-2500-2500 if a machine was detected due to some unusual silence when starting the call.
TimestampdatetimeThe date-time the AMD occurred, in RFC 3339 format (e.g. 2020-08-03T15:58:41.56831062Z).
Notification icon

At the moment AMD configuration is limited to json callflows and XML callflows may only use the `IfMachine` attribute for Say steps.

Conditionals

Call flow steps can be programmed to be executed depending on which key is pressed in an IVR menu. This is a bit more straightforward and easy to code with XML as shown in the if tag but gets more complex when using JSON because there is no way of grouping actions together.

In JSON each step can have a conditions array of condition objects.

Condition object

OptionTypeDescription
variablestringThe name of the variable to check its value. This would be set in previous steps via the onKeypressVar option of say/play/pause steps.
operatorstring== for equality or != for inequality of the variable contents against contents of the value option.
valuestringThe value to compare with the variable contents.

Each action that needs to be executed under specific conditions must have them defined in the conditions option array. When looking for an action to execute next, the callflow will continue with the first action that follows the last executed step that either has all its conditions evaluated as true or has no conditions.

Let's consider the following example:

{
"steps": [
{
"action": "say",
"options": {
"payload": "press 1 to talk to department A, press 2 to talk to department B",
"language": "en-US",
"voice": "male"
},
"onKeypressVar": "digitpressed",
"onKeypressGoto": "transferdept"
},
{
"action": "pause",
"options": {
"length": "5s"
},
"onKeypressVar": "digitpressed",
"onKeypressGoto": "transferdept"
},
{
"action": "say",
"options": {
"payload": "you didn't press anything. Hanging up",
"language": "en-US",
"voice": "male"
}
},
{
"action": "hangup"
},
{
"id": "transferdept",
"action": "say",
"options": {
"payload": "you are being transferred to department A",
"language": "en-US",
"voice": "male"
},
"conditions": [
{
"variable": "digitpressed",
"condition": "==",
"value": "1"
}
]
},
{
"action": "transfer",
"options": {
"destination": "316123456781"
},
"conditions": [
{
"variable": "digitpressed",
"condition": "==",
"value": "1"
}
]
},
{
"action": "say",
"options": {
"payload": "you are being transferred to department B",
"language": "en-US",
"voice": "male"
},
"conditions": [
{
"variable": "digitpressed",
"condition": "==",
"value": "2"
}
]
},
{
"action": "transfer",
"options": {
"destination": "35123123123"
},
"conditions": [
{
"variable": "digitpressed",
"condition": "==",
"value": "2"
}
]
},
{
"action": "say",
"options": {
"payload": "goodbye",
"language": "en-US",
"voice": "male"
}
}
]
}

In the scenario above the user is presented with an IVR (Interactive voice response) menu. They can choose to be transfered to one of the 2 departments available. If no key is pressed or the wrong key is pressed we'll say something different and hangup.

There are a few key points to pay attention to:

  • We use the same onKeypressVar and onKeypressGoto parameters on both the say and the pause so keypresses during the say step and right after are treated equally.
  • Right after these two prompting steps we have a say and a hangup step to catch the case where the user did not press anything.
  • The step following the hangup has the id parameter set to transferdept which is the same value as the onKeypressGoto. This makes the callflow skip the hangup steps if any key is pressed.
  • Each step after and including the step with id set to transferdept has a conditions array apart from the last step.
  • onKeypressGoto does not mean that the step to go to will be executed as the step's conditions might not evaluate to true. For example if the user pressed 2 the steps responsible for transfering to department A will be skipped.
  • If the user pressed 3 since all conditions are strictly checking against the values 1 and 2 the step to be executed will be the last one as that has no conditions set. After that the call will hangup as there are no more steps to execute.

Dynamic call flows

Call flows can be statically created as described in the Creating a call flow. However, you might want something dynamic to happen based on business logic inside your application or organization. For example: Transfer an incoming call to a 24/7 support line when the caller is a priority customer.

To achieve this, our platform can retrieve a call flow from your web service as a call is being received. Your web service can then dynamically provide the call flow to execute, based on the properties of the incoming call (e.g. the caller ID or the dialed number).

Notification icon

When there is a failure during the fetching of the call-flow, for example a time-out or a wrong attribute, you can look at the logs in the dashboard.

Setup

First, create a call flow with a fetchCallFlow step (as detailed above), passing the URL of your web service as a url step option.

Example request to create a fetch callflow

curl -X POST https://voice.messagebird.com/call-flows \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-H "Content-Type: application/json" \
-d $'{
"steps": [
{
"options": {
"url": "https://example.com"
},
"action": "fetchCallFlow"
}
]
}'

Usage

Next, incoming calls will trigger an HTTP request to the configured URL with the following parameters:

Parameters
ParametersExampleDescription
callID1ebbae0e-e1a6-4b85-8ccb-de609d0b4510The unique ID of the call.
destination31612345678The destination number that is/was called.
firstLegDirectionoutgoing/incomingCan be either 'incoming' or 'outgoing' and be used to distinguish whether the originating call was an incoming one or triggered via the API
source31644556677/anonymousThe source number that triggered the call. Only owned or verified numbers can be used. See allowed caller IDs
variables{"user_pressed": "5"}Json object containing metadata of the call. Can include key presses if used together with onKeypressVar in steps or via the Flow Builder.

In case the previous step is a Transfer or a MaskedTransfer step the variables parameter will contain these additional fields:

  • TransferLegID: the UUID of the transfer leg;
  • TransferLegStatus: the status of the transfer leg;
  • TransferLegDuration: the duration in seconds of the transfer leg.

Example incoming request to your web service

GET /?callID=97f9b1d2-b8b4-4db7-8829-ec3e660d2cdb&destination=19027064857&firstLegDirection=incoming&source=%2B31611171210&variables=%7B%22testingvar%22%3A%222%22%7D HTTP/1.1
Host: example.com
Accept-encoding: gzip
User-Agent: Go-http-client/1.1
X-MessageBird-Signature: OomF7gSVo5TdL6mxFvdlYodiTnJtPaEk7V6czObUUI0=
Connection: keep-alive

When receiving an incoming HTTP request, your platform should respond with either an XML or JSON call flow (see: The call flow object). Additionally, the response should have a 200 OK status code, and a Content-Type HTTP header with application/xml or application/json as the value, based on what type of call flow you return.

Example HTTP Response Body (XML Call Flow)

<?xml version="1.0" encoding="UTF-8"?>
<CallFlow>
<Say language="en-GB" voice="female">The quick brown fox jumped over the lazy dog.</Say>
<Hangup/>
</CallFlow>
Notification icon

When a statically created call flow contains a `fetchCallFlow` step, the fetched call flow will be executed and overrides the previous call flow for the call. If a call flow contained steps after a `fetchCallFlow` step, those will not be executed.

Validation of signatures

Notification icon

Voice signature generation used for fetching dynamic call flows differs from both the signature generation used in Voice webhooks and the generic signature generation used by other MessageBird services

Each Dynamic Call Flow HTTP request is signed with a signature when provided with a token, a base64 encoded HMAC found in the X-MessageBird-Signature HTTP header. To ensure the callback is coming from the MessageBird platform, we strongly advise you to validate its signature by calculating the HMAC of the callback and base64 encoding it.

Using HMAC-SHA256, the HTTP QUERY PARAMS are the message and the optional token of the related fetchCallFlow step is the secret.

Signature simulation example

# Emulate the X-Messagebird-Signature generation from the command line using openssl and base64.
$ echo -n 'callID=97f9b1d2-b8b4-4db7-8829-ec3e660d2cdb&destination=19027064857&firstLegDirection=incoming&source=%2B31611171210&variables=%7B%22testingvar%22%3A%222%22%7D'| openssl dgst -sha256 -hmac "some-custom-token" -binary |base64
v3HpIXiFBDvwiwA4wwgRg6T85Vs7o74w8wAvkOoyDo8=

Pseudocode example

// Note that the query params should be sorted by alphabetically order of the keys including the variables array
signature = HMAC_SHA_256(
QUERY_PARAMS,
signing_key
)
if HMAC_EQUALS(signature, BASE_64_DECODE(request_signature)) {
// Yay!
}

Calls

A call describes a voice call.

A call is made to a number. A call has legs which are incoming or outgoing voice connections. An incoming leg is created when somebody calls a number. Outgoing legs are created when a call is transferred.

URI

https://voice.messagebird.com/calls

Available HTTP Methods

POST /calls/
GET /calls/
GET /calls/{callID}
PUT /calls/{callID}
DELETE /calls/{callID}
POST /calls/{callID}/{destination}
GET /calls/{callID}/legs
GET /calls/{callID}/legs/{legID}
DELETE /legs/{legID}
POST /legs/{legID}/hold
POST /legs/{legID}/unhold

The call object

This is an object representing a voice call at MessageBird.com.

Attributes

AttributeTypeDescription
idstringThe unique ID of the call.
statusstringThe status of the call. Possible values: queued, starting, ongoing, ended.
sourcestringThe source number of the call, without leading +, ommited if not available. Only owned or verified numbers can be used. See allowed caller IDs
sourcePoolstringNumber pool name to use to select a source number. Can't be specified when using source.
destinationstringThe destination number of the call, without leading +, ommited if not available
webhook.urlstringThe URL to use for status callbacks. See: webhooks.
webhook.tokenstringThe token to use for status callbacks. See: webhooks
createdAtdatetimeThe date-time the call was created, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
updatedAtdatetimeThe date-time the call was last updated, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
endedAtdatetimeThe date-time the call ended, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).

Call object example

{
"id": "f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58",
"status": "ended",
"source": "31644556677",
"destination": "31612345678",
"createdAt": "2017-02-16T10:52:00Z",
"updatedAt": "2017-02-16T10:59:04Z",
"endedAt": "2017-02-16T10:59:04Z"
}

List all calls

This request retrieves a listing of all calls.

Response

If successful, this request will return an object with a data, _links and pagination properties. If the request failed, an error object will be returned.

The data property is an array of call objects, can be null if there are no calls. The _links property is an object with HATEOAS links related to the object listing. The pagination property is an object with details about the result page count, total count, and pagination numbers.

Notification icon

To ensure high availability, the `totalCount` value returned from `GET /calls` may return `999999999` when determining the precise count takes more than 2 seconds to calculate. Because this pagination value may be unreliable, we recommend checking that the data property of the response object is not null when scripting requests as you can expect that this value will be null when no results have been found.

Definition

GET https://voice.messagebird.com/calls

Example request

curl -X GET "https://voice.messagebird.com/calls" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58",
"status": "ended",
"source": "31644556677",
"destination": "31612345678",
"createdAt": "2017-02-16T10:52:00Z",
"updatedAt": "2017-02-16T10:59:04Z",
"endedAt": "2017-02-16T10:59:04Z",
"_links": {
"self": "/calls/f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58"
}
},
{
"id": "ac07a602-dbc1-11e6-bf26-cec0c932ce01",
"status": "ended",
"source": "31644556677",
"destination": "31612345678",
"createdAt": "2017-01-16T07:51:56Z",
"updatedAt": "2017-01-16T07:55:56Z",
"endedAt": "2017-01-16T07:55:56Z",
"_links": {
"self": "/calls/ac07a602-dbc1-11e6-bf26-cec0c932ce01"
}
}
],
"_links": {
"self": "/calls?page=1"
},
"pagination": {
"totalCount": 2,
"pageCount": 1,
"currentPage": 1,
"perPage": 10
}
}

Viewing a call

This request retrieves a call resource. The single parameter is the unique ID that was returned upon creation.

Required parameters
ParameterTypeDescriptionRequired
idstringThe unique ID of a call generated upon creation.Yes

Response

If successful, this request will return an object with a data property, which is an array that has a single call object. If the request failed, an error object will be returned.

Definition

GET https://voice.messagebird.com/calls/{callID}

Example request

curl -X GET https://voice.messagebird.com/calls/f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58 \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'

Example response

{
"data": [
{
"id": "f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58",
"status": "ended",
"source": "31644556677",
"destination": "31612345678",
"createdAt": "2017-02-16T10:52:00Z",
"updatedAt": "2017-02-16T10:59:04Z",
"endedAt": "2017-02-16T10:59:04Z"
}
],
"_links": {
"self": "/calls/f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58"
}
}

Creating a call

This request initiates an outbound call. When placing a call, you pass the source (the caller ID), the destination(the number/address that will be called), and the callFlow (the call flow to execute when the call is answered).

Required parameters
ParameterTypeDescription
sourcestringThe caller ID of the call. Only owned or verified numbers can be used. See allowed caller IDs
destinationstringThe number/address to be called. This can be an E.164 formatted number, SIP URI or Client URI. E.g. 31612345678, sip:foobar@example.com, or client:name_of_client.
callFlowobjectThe call flow object to be executed when the call is answered.
Optional parameters
ParameterTypeDescription
callFlow.noAnswerTimeoutintegerRinging timeout for not answered call in seconds. Must be set in the callFlow object of the call. Minimum: 20. Maximum: 90. Default: 30.
callFlow.maxDurationinteger or stringMaximum duration of the call in seconds or as a string. Can contain units of time: e.g. 50s/10m/2h. Minimum: "30s". Maximum: "8h". Default: "8h".
webhook.urlstringThe URL to use for status callbacks. See: webhooks. Setting a webhook URL when creating a call will override any webhook resource settings if they exist.
webhook.tokenstringThe token to use for status callbacks. See: webhooks.

Response

If successful, this request will return an object with a data property, which is an array that has a single call object. If the request failed, an error object will be returned.

Definition

POST https://voice.messagebird.com/calls

Example request

curl -X POST https://voice.messagebird.com/calls \
-H "Content-Type: application/json" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-d $'{
"source": "31644556677",
"destination": "31612345678",
"callFlow": {
"steps": [
{
"action": "say",
"options": {
"payload": "This is a journey into sound. Good bye!",
"voice": "male",
"language": "en-US"
}
}
]
},
"webhook": {
"url": "https://example.com",
"token": "token_to_sign_the_call_events_with"
}
}'

Example response

{
"data": [
{
"id": "21025ed1-cc1d-4554-ac05-043fa6c84e00",
"status": "queued",
"source": "31644556677",
"destination": "31612345678",
"createdAt": "2017-08-30T07:35:37Z",
"updatedAt": "2017-08-30T07:35:37Z",
"endedAt": null
}
],
"_links": {
"self": "/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00"
}
}

Updating a call

This request updates an active call. You can update steps of an ongoing call by providing a new call-flow url. When you update the call through the API, the API will request the new call-flow at the by you provided new URL. Once the new call-flow is fetched, current ongoing steps will be stopped and the new call-flow will be executed.

Required parameters
ParameterTypeDescriptionRequired
fetchCallFlowUrlstringThe URL to fetch the new call flow from. See: Dynamic call flows.Yes
Optional parameters
ParameterTypeDescriptionRequired
fetchCallFlowTokenstringThe token that we will use to sign the request. See: Dynamic call flows.No

Response

If successful, this request will return an object with a data property, which is an array that has a single call object. If the request failed, an error object will be returned.

Definition

PUT https://voice.messagebird.com/calls/{callID}

Example request

curl -X PUT https://voice.messagebird.com/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00 \
-H "Content-Type: application/json" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-d $'{
"fetchCallFlowUrl": "https://www.example.com",
"fetchCallFlowToken": "foobar"
}'

Example response

{
"data": [
{
"id": "21025ed1-cc1d-4554-ac05-043fa6c84e00",
"status": "ongoing",
"source": "31644556677",
"destination": "31612345678",
"createdAt": "2017-08-30T07:35:37Z",
"updatedAt": "2017-08-30T07:35:37Z",
"endedAt": null
}
],
"_links": {
"legs": "/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00/legs",
"self": "/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00"
}
}

Deleting a call

This request will hang up all the legs of the call.

Required parameters
ParameterTypeDescriptionRequired
idstringThe unique ID of the call.Yes

Response

If successful, this request returns an HTTP header of 204 No Content and an empty response. If the request failed, an error object will be returned.

Definition

DELETE https://voice.messagebird.com/calls/{callID}

Example request

curl -X DELETE https://voice.messagebird.com/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00 \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'

Add participant to call

This request will add a new destination number to an ongoing call. The new participant will receive the call, by default, with a caller ID matching the call originator's number. This can be overriden with the source parameter as described below.

Notification icon

This endpoint should only be used for Inbound calls. Unexpected behavior may result for Outbound originated calls in either how the call ends, or how the remaining steps of the Call Flow proceed.

Request Parameters
ParameterTypeDescriptionRequired
callIDstringThe unique ID of the call.Yes
destinationstringThe destination (E.164 formatted number, SIP URI or Client URI) to transfer a call to. E.g. 31612345678, sip:foobar@example.com, or client:name_of_client. The Client URI is in early access at this moment as part of our Client SDK.Yes
sourcestringA source parameter can be added to the body of the request to override the Caller ID displayed for the new call participant.No

Definition

POST https://voice.messagebird.com/calls/{callID}/{destination}

Example request

curl -X POST https://voice.messagebird.com/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00/31612345678 \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-d $'{"source": "310123456789"}'

Legs

A leg describes a leg object (inbound or outbound) that belongs to a call. At least one leg exists per call.

Inbound legs are being created when an incoming call to a Number is being initiated.

Outbound legs are created when a call is transferred or when a call is being originated from the API.

URI

https://voice.messagebird.com/calls/{callID}/legs

Available HTTP Methods

GET /calls/{callID}/legs
GET /calls/{callID}/legs/{legID}
DELETE /legs/{legID}
POST /legs/{legID}/hold
POST /legs/{legID}/unhold

The leg object

This is an object representing a leg at MessageBird.com.

Attributes

AttributeTypeDescription
idstringThe unique ID of the leg.
callIDstringThe unique ID of the call that this leg belongs to.
sourcestringThe number/SIP/Client URL that is making the connection.
destinationstringThe number/SIP/Client URL that a connection is made to.
sipResponseCodeintegerIf applicable, provides the final SIP status code for the leg. If not available, this field will not be returned. Possible values are listed here.
statusstringThe status of the leg. Possible values: starting, ringing, ongoing, busy, no_answer, failed and hangup.
directionstringThe direction of the leg, indicating if it's an incoming connection or outgoing (e.g. for transferring a call). Possible values: incoming, outgoing.
costfloatThe cost of the leg. The amount relates to the currency parameter.
currencystringThe three-letter currency code (ISO 4217) related to the cost of the leg.
durationintegerThe duration of the leg, in seconds.
createdAtdatetimeThe date-time the leg was created, in RFC 3339 format (e.g.2017-03-06T13:34:14Z).
updatedAtdatetimeThe date-time the leg was last updated, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
answeredAtdatetimeThe date-time the leg was answered, in RFC 3339 format (e.g.2017-03-06T13:34:14Z).
endedAtdatetimeThe date-time the leg ended, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).

Object example

{
"id": "d4f07ab3-b17c-44a8-bcef-2b351311c28f",
"callId": "f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58",
"source": "31644556677",
"destination": "31612345678",
"status": "hangup",
"sipResponseCode": 200,
"direction": "outgoing",
"duration": 31,
"createdAt": "2017-02-16T10:52:00Z",
"updatedAt": "2017-02-16T10:52:30Z",
"answeredAt": "2017-02-16T10:52:30Z",
"endedAt": "2017-02-16T10:52:30Z"
}

List all legs

This request retrieves a listing of all legs.

Required parameters
ParameterTypeDescriptionRequired
idstringThe unique ID of a call generated upon creation.Yes

Response

If successful, this request will return an object with a data property containing the leg objects, can be null if there are no legs. If the request failed, an error object will be returned. The _links property is an object with HATEOAS links related to the object listing. The pagination property is an object with details about the result page count, total count, and pagination numbers.

Notification icon

To ensure high availability, the `totalCount` value returned from `GET /legs` may return `999999999` when determining the precise count takes more than 2 seconds to calculate. Because this pagination value may be unreliable, we recommend checking that the data property of the response object is not null when scripting requests as you can expect that this value will be null when no results have been found.

Definition

GET https://voice.messagebird.com/calls/{callID}/legs

Example request

curl -X GET "https://voice.messagebird.com/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00/legs" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "d4f07ab3-b17c-44a8-bcef-2b351311c28f",
"callId": "f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58",
"source": "31123456789",
"destination": "31123456777",
"status": "hangup",
"sipResponseCode": 200,
"direction": "outgoing",
"duration": 31,
"cost": 0.000385,
"currency": "USD",
"createdAt": "2017-02-16T10:52:00Z",
"updatedAt": "2017-02-16T10:52:30Z",
"answeredAt": "2017-02-16T10:52:30Z",
"endedAt": "2017-02-16T10:52:30Z",
"_links": {
"self": "/calls/f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58/legs/d4f07ab3-b17c-44a8-bcef-2b351311c28f"
}
},
{
"id": "e60ca497-0cf3-4954-b74c-265e95633ec8",
"callId": "f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58",
"source": "31123456789",
"destination": "31123456788",
"status": "hangup",
"sipResponseCode": 200,
"direction": "incoming",
"duration": 31,
"cost": 0.000385,
"currency": "USD",
"createdAt": "2017-02-16T10:52:00Z",
"updatedAt": "2017-02-16T10:52:30Z",
"answeredAt": "2017-02-16T10:52:30Z",
"endedAt": "2017-02-16T10:52:30Z",
"_links": {
"self": "/calls/f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58/legs/e60ca497-0cf3-4954-b74c-265e95633ec8"
}
}
],
"_links": {
"self": "/calls/f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58/legs?page=1"
},
"pagination": {
"totalCount": 2,
"pageCount": 1,
"currentPage": 1,
"perPage": 10
}
}

Viewing a leg

This request retrieves a leg resource. The parameters are the unique ID of the call and of the leg that were returned upon their respective creation.

Required parameters

ParameterTypeDescriptionRequired
callIDstringThe unique ID of a call generated upon creation.Yes
legIdstringThe unique ID of a leg generated upon creation.Yes

Response

If successful, this request returns an object with a data property, which is an array that has a single call object. If the request failed, an error object will be returned.

Definition

GET https://voice.messagebird.com/calls/{callID}/legs/{legID}

Example request

curl -X GET https://voice.messagebird.com/calls/21025ed1-cc1d-4554-ac05-043fa6c84e00/legs/d4f07ab3-b17c-44a8-bcef-2b351311c28f \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'

Example response

{
"data": [
{
"id": "d4f07ab3-b17c-44a8-bcef-2b351311c28f",
"callId": "f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58",
"source": "31644556677",
"destination": "31612345678",
"status": "hangup",
"sipResponseCode": 200,
"direction": "outgoing",
"duration": 31,
"cost": 0.000385,
"currency": "USD",
"createdAt": "2017-02-16T10:52:00Z",
"updatedAt": "2017-02-16T10:52:30Z",
"answeredAt": "2017-02-16T10:52:30Z",
"endedAt": "2017-02-16T10:52:04Z"
}
],
"_links": {
"self": "/calls/f1aa71c0-8f2a-4fe8-b5ef-9a330454ef58/legs/d4f07ab3-b17c-44a8-bcef-2b351311c28f"
}
}

Deleting a leg

This request deletes a leg which will result in the leg being immediately disconnected. In a two-way conversation, performing this operation on any leg will hangup the call as a whole.

The parameters are the unique ID of the leg.

Required parameters
ParameterTypeDescriptionRequired
legIdstringThe unique ID of a leg generated upon creation.Yes

Response

If successful or if either the call or the requested leg is already in a final status, this request will return an HTTP header of 204 No Content and an empty response. If the request failed, an error object will be returned.

Definition

DELETE https://voice.messagebird.com/legs/{legID}

Example request

curl -X DELETE "https://voice.messagebird.com/legs/07fda3f9-ddd3-4267-ab01-71cf55df31df" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Place a Leg on Hold

This request places a leg on hold. This results in the caller on that leg being placed in a state separate from the rest of the call participants, unable to hear or speak to other callers.

Audio can be played to the user with the musicOnHold parameter. Note that if not specified, the user will hear silence during the hold. If specified, the audio provided will be played on loop for the duration of the hold.

Required parameters
ParameterTypeDescription
legIdstringThe unique ID of a leg generated upon creation.
Optional parameters
ParameterTypeDescription
musicOnHoldstringAudio to play to the user on hold.

Definition

POST https://voice.messagebird.com/legs/{legID}/hold

Example request

curl -X POST "https://voice.messagebird.com/legs/07fda3f9-ddd3-4267-ab01-71cf55df31df/hold" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"\
-d $'{"musicOnHold": "https://path.to/hold-music.wav"}'

Remove a Leg from Hold

This request removes a leg from hold. This results in the caller rejoining the other call participant(s) after having been on hold.

Required parameters
ParameterTypeDescription
legIdstringThe unique ID of a leg generated upon creation.

Definition

POST https://voice.messagebird.com/legs/{legID}/unhold

Example request

curl -X POST "https://voice.messagebird.com/legs/07fda3f9-ddd3-4267-ab01-71cf55df31df/unhold" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

SIP Status Codes

Leg objects returned from HTTP requests and via Webhooks that return a leg object may contain a sipResponseCode field if a SIP Status could be determined for a leg. Because this is in some situations not possible, this field may not always be returned. The following table provides an overview of the SIP statuses that MessageBird currently provides. Note that only the numerical value of the SIP Status will be returned.

SIP StatusDescriptionCommon Cause
200 - OKSuccessfulThe call was connected and completed successfully.
403 - ForbiddenThe server understood the request, but is refusing to fulfill it.The user or the network might have rejected the call. Typically by pressing the reject button on a mobile phone. Occasionally the destination number might not be allowed to be dialed from your account, for example for high-cost destinations such as premium numbers. If this occurs, please contact support.
404 - Not FoundThe server has definitive information that the user does not exist at the domain specified in the Request-URI.The number is unallocated to a subscriber or does not exist. Please check if the number is correct and in the correct international format.†
408 - Request TimeoutCouldn't find the user in time.This could happen when the called party's mobile phone did not respond to the network, typically when there is no cellular / mobile signal or when the battery has died. In case your account ran out of sufficient balance to place the call this resonse code is also used.
410 - GoneThe user existed once, but is not available here any more.This could happen when the number has changed and is not allocated anymore.
480 - Temporarily UnavailableCallee currently unavailable.This could happen when the called party's mobile phone did not respond to the network, typically when there is no cellular / mobile signal or when the battery has died. This code may also be used if the user rejects the call, or your account has insufficient balance to place the call.
484 - Address IncompleteRequest-URI incomplete.The number does not contain enough digits or does not exist. Please check if the number is correct and in the correct international format.†
486 - Busy HereCallee is busy.The destination is valid, but the user was busy with another call.
488 - Not Acceptable HereSome aspect of the session description or the Request-URI is not acceptable.Typically this indicates the used codecs on a SIP trunking call are not accepted, in rare cases it could also be related to either the number of the called or calling party.
500 - Internal Server ErrorThe server could not fulfill the request due to some unexpected condition.This could indicate an internal server error at one of the MessageBird servers or a downstream carrier. If this happens only for a certain number please check if the number is correct and in the correct international format.†
501 - Not ImplementedThe server does not have the ability to fulfill the request, such as because it does not recognize the request method.This error comes from a downstream carrier. If this happens only for a certain number please check if the number is correct and in the correct international format.†
502 - Bad GatewayThe server is acting as a gateway or proxy, and received an invalid response from a downstream server while attempting to fulfill the request.This error comes from a downstream carrier. If this happens only for a certain number please check if the number is correct and in the correct international format.†
503 - Service UnavailableThe server is undergoing maintenance or is temporarily overloaded and so cannot process the request.This could indicate unavailability of one of the MessageBird servers or of a downstream carrier. If this happens only for a certain number please check if the number is correct and in the correct international format.†

† When dialing internationally, it is often required that the number begins with a country code and omits any "trunk prefixes" like 0.


Recordings

A recording describes a voice recording of a leg. You can initiate a recording of a leg by having a step in your callflow with the record action set.

URI

https://voice.messagebird.com/calls/{callID}/legs/{legID}/recordings

Available HTTP Methods

GET /calls/{callID}/legs/{legID}/recordings
GET /recordings/{recordingID}
GET /recordings/{recordingID}.wav
# DEPRECATED:
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}.wav

The recording object

This is an object representing a recording.

Attributes

AttributesTypeDescription
idstringThe unique ID of the recording.
formatstringThe format of the recording. Supported formats are: wav.
typestringThe type of the recording, possible values are ivr(result of a record step), transfer(result of a transfer step recording) or call(in case of full call recording).
legIdstringThe ID of the leg that the recording belongs to.
statusstringThe status of the recording. Available statuses are:initialised, recording, done and failed
durationintegerThe duration of the recording in seconds.
createdAtdatetimeThe date-time the recording entry was created, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
updatedAtdatetimeThe date-time the recording entry was last updated, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
startedAtdatetimeThe date-time the recording was started, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z). Might be null for older recordings.
finishedAtdatetimeThe date-time the recording was finished, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z). Might be null for older recordings.
_linkshashA hash with HATEOAS links related to the object. This includes the file link that has the URI for downloading the wave file of the recording.

Object example

{
"data": [
{
"id": "3b4ac358-9467-4f7a-a6c8-6157ad181123",
"format": "wav",
"legId": "227bd14d-3eee-4380-b01f-fe7723c69a31",
"status": "done",
"duration": 7,
"createdAt": "2017-05-17T11:42:57Z",
"updatedAt": "2017-05-17T11:43:04Z",
"startedAt": "2017-05-17T11:43:03Z",
"finishedAt": "2017-05-17T11:43:10Z"
}
],
"_links": {
"self": "/recordings/3b4ac358-9467-4f7a-a6c8-6157ad181123",
"file": "/recordings/3b4ac358-9467-4f7a-a6c8-6157ad181123.wav"
}
}

Viewing a recording

This request retrieves a recording resource. The parameters are the unique ID of the recording, the leg and the call with which the recording is associated.

Required parameters

ParameterTypeDescriptionRequired
callIDstringThe unique ID of a call generated upon creation.Yes
legIdstringThe unique ID of a leg generated upon creation.Yes
recordingIdstringThe unique ID of a recording generated upon creation.Yes

Response

If successful, this request returns an object with a data property, which is an array that has a single recording object. If the request failed, an error object will be returned. The _links property is an object with HATEOAS links related to the object listing. The pagination property is an object with details about the result page count, total count, and pagination numbers.

Notification icon

To ensure high availability, the `totalCount` value returned from `GET /recordings` may return `999999999` when determining the precise count takes more than 2 seconds to calculate. Because this pagination value may be unreliable, we recommend checking that the data property of the response object is not null when scripting requests as you can expect that this value will be null when no results have been found.

Definition

GET https://voice.messagebird.com/recordings/{recordingID}

Example request

curl -X GET "https://voice.messagebird.com/recordings/4c2ac358-b467-4f7a-a6c8-6157ad181142" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"_links": {
"self": "/recordings/796c6d68-d307-46c0-8925-05bf069a7d14",
"transcriptions": "/recordings/796c6d68-d307-46c0-8925-05bf069a7d14/transcriptions"
},
"data": [
{
"id": "796c6d68-d307-46c0-8925-05bf069a7d14",
"format": "wav",
"legId": "a6a2a420-bed7-4200-b87b-3d20e6a258c3",
"status": "done",
"duration": 18,
"type": "call",
"createdAt": "2020-05-19T06:43:34Z",
"updatedAt": "2020-05-19T06:43:55Z",
"deletedAt": null,
"startedAt": "2020-05-19T06:43:34Z",
"finishedAt": "2020-05-19T06:43:55Z",
"_links": {
"file": "/recordings/796c6d68-d307-46c0-8925-05bf069a7d14.wav",
"self": "/recordings/796c6d68-d307-46c0-8925-05bf069a7d14"
}
}
]
}

List recordings

To list all recordings, you can do a GET request on the /recordings endpoint. The parameters are the unique ID of the recording, as well as filters detailed below.

Required parameters

ParameterTypeDescriptionRequired
callIDstringThe unique ID of a call generated upon creation.Yes
legIdstringThe unique ID of a leg generated upon creation.Yes

Filters

Besides listing all Recordings, the MessageBird Voice Recordings API also provides some filters that can be used as query parameters:

FilterTypeDescription
limitintegerLimit the amount of recordings listed.
offsetintegerSkip first n results.

Response

If successful, this request returns an object with a list of recordings, which is an array. If the request failed, an error object will be returned.

Definition

GET https://voice.messagebird.com/calls/{callID}/legs/{legID}/recordings

Example request

curl -X GET "https://voice.messagebird.com/calls/fdcf0391-4fdc-4e38-9551-e8a01602984f/legs/317bd14d-3eee-4380-b01f-fe7723c6913a/recordings" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Downloading the recording file

The file HATEOAS link has the appropriate URI for downloading a wave file for the recording. The file is accessible only if you provide the correct API access key for your account and the recording is for a leg/call in your account.

URI

/recordings/{recordingID}.wav

Definition

GET https://voice.messagebird.com/recordings/{recordingID}.wav

Example request

curl -X GET "https://voice.messagebird.com/recordings/4c2ac358-b467-4f7a-a6c8-6157ad181142.wav" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Possible responses

Status codeDescription
200Request has succeeded. It is possible that recording file is partially served.
404Requested recording doesn't exist.

Deleting a recording

This request deletes a recording. The parameters are the unique ID of the recording, the leg and the call with which the recording is associated.

Required parameters
ParameterTypeDescriptionRequired
callIDstringThe unique ID of a call generated upon creation.Yes
legIdstringThe unique ID of a leg generated upon creation.Yes
recordingIdstringThe unique ID of a recording generated upon creation.Yes

Response

If successful, this request will return an HTTP header of 204 No Content and an empty response. If the request failed, an error object will be returned.

Definition

DELETE https://voice.messagebird.com/recordings/{recordingID}

Example request

curl -X DELETE "https://voice.messagebird.com/recordings/07fda3f9-ddd3-4267-ab01-71cf55df31df" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Transcriptions

A transcription is a textual representation of a recording as text. You can request an automated transcription for a recording by doing a POST request to the API.

MessageBird supports several languages: de-DE, en-AU, en-UK, en-US, es-ES, es-LA, fr-FR, it-IT, nl-NL, pt-BR. We expect to release support for more languages soon.

URI

https://voice.messagebird.com/recordings/{recordingID}/transcriptions

Available HTTP Methods

GET /recordings/{recordingID}/transcriptions
POST /recordings/{recordingID}/transcriptions
GET /transcriptions/{transcriptionID}
GET /transcriptions/{transcriptionID}.txt
# DEPRECATED:
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions/{transcriptionID}
GET /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions/{transcriptionID}.txt
POST /calls/{callID}/legs/{legID}/recordings/{recordingID}/transcriptions

The transcription object

This is an object representing a transcription.

Attributes

AttributeTypeDescription
idstringThe unique ID of the transcription.
recordingIdstringThe ID of the recording that the transcription belongs to.
statusstringThe status of the transcription. Possible values: created, transcribing, done, failed.
createdAtdatetimeThe date-time the transcription was created/requested, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
updatedAtdatetimeThe date-time the transcription was last updated, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
_linkshashA hash with HATEOAS links related to the object. This includes the file link that has the URI for downloading the text transcription of a recording.

Transcription object example

{
"data": [
{
"id": "87c377ce-1629-48b6-ad01-4b4fd069c53c",
"recordingId": "123da3f9-ddd3-4267-ab01-71cf55df31df",
"status": "done",
"createdAt": "2017-06-20T10:03:14Z",
"updatedAt": "2017-06-20T10:03:14Z"
}
],
"_links": {
"self": "/transcriptions/87c377ce-1629-48b6-ad01-4b4fd069c53c",
"file": "/transcriptions/87c377ce-1629-48b6-ad01-4b4fd069c53c.txt"
}
}

Creating a transcription request

In order to create a transcription request for an existing recording, you must do a POST request to the following URI:

URI

https://voice.messagebird.com/recordings/{recordingID}/transcriptions

A transcription request is asynchronous. That means that it will take some time before the result has been generated. This depends on the total duration of the recording.

Required parameters

ParameterTypeDescriptionRequired
recordingIdstringThe unique ID of a recording generated upon creation.Yes
languagestringThe language of the recording that is to be transcribed. Allowed values: de-DE, en-AU, en-UK, en-US, es-ES, es-LA, fr-FR, it-IT, nl-NL, pt-BR.Yes

Response

If successful, this request returns an object with a data property, which is an array that has a single transcription object. If the transcription request failed, an error object will be returned. The _links property is an object with HATEOAS links related to the object listing. The pagination property is an object with details about the result page count, total count, and pagination numbers.

Notification icon

To ensure high availability, the `totalCount` value returned from `GET /transcriptions` may return `999999999` when determining the precise count takes more than 2 seconds to calculate. Because this pagination value may be unreliable, we recommend checking that the data property of the response object is not null when scripting requests as you can expect that this value will be null when no results have been found.

Example request

curl -X POST "https://voice.messagebird.com/recordings/07fda3f9-ddd3-4267-ab01-71cf55df31df/transcriptions/" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-d $'{
"language": "en-EN"
}'

Viewing a transcription

This request retrieves a transcription resource. The parameters are the unique ID of the recording, the leg and, the call with which this recording is associated.

Required parameters

ParameterTypeDescriptionRequired
recordingIdstringThe unique ID of a recording generated upon creation.Yes

Response

If successful, this request returns an object with a data property, which is an array that has a single transcription object. If the request failed, an error object will be returned.

Definition

GET https://voice.messagebird.com/recordings/{recordingID}/transcriptions

Example request

curl - X GET "https://voice.messagebird.com/transcriptions/87c377ce-1629-48b6-ad01-4b4fd069c53c" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "87c377ce-1629-48b6-ad01-4b4fd069c53c",
"recordingId": "07fda3f9-ddd3-4267-ab01-71cf55df31df",
"status": "done",
"createdAt": "2017-06-20T10:03:14Z",
"updatedAt": "2017-06-20T10:03:14Z",
"_links": {
"self": "/transcriptions/87c377ce-1629-48b6-ad01-4b4fd069c53c",
"file": "/transcriptions/87c377ce-1629-48b6-ad01-4b4fd069c53c.txt"
}
}
}

Downloading the transcription file

The file HATEOAS link has the appropriate URI for downloading a text file for the transcription. The file is accessible only if you provide the correct API access key for your account and the transcription is for a recording/leg/call in your account.

The format of this URI is:

/transcriptions/{transcriptionID}.txt

Numbers

A number is a MessageBird number purchased with the voice feature. You can query voice-specific number details. The numbers can have callflows and webhooks associated with them.

URI

https://voice.messagebird.com/numbers

Available HTTP Methods

GET /numbers
GET /numbers/{number}/call-flow
POST /numbers/{number}/webhook
GET /numbers/{number}/webhook

The number object

This is an object representing a number. It has number and voice specific metadata

Attributes

AttributeTypeDescription
idstringThe unique ID of the purchased number.
numberstringThe phone number
callFlowIdstringThe unique ID of call flow associated if any.
createdAtdatetimeThe date-time the number was purchased, in RFC 3339 format (e.g. 2018-10-24T16:12:03Z).
updatedAtdatetimeThe date-time the number was last updated, in RFC 3339 format (e.g. 2018-10-24T16:12:03Z)

Number object example

{
"id": "d212d28a-bfe7-1235-1abd-f01fafdf8755",
"number": "31123456789",
"callFlowId": "200d95ee-4fcf-46e7-b75a-32a26cb6ebf4",
"createdAt": "2019-11-11T14:53:47Z",
"updatedAt": "2020-07-30T14:30:11Z"
}

List all numbers

This request retrieves a listing of all numbers with the voice feature.

URI

https://voice.messagebird.com/numbers

Response

If successful, the request will return an object with data, _links and pagination properties. If the request failed, an error object will be returned.

The data property is an array of number objects. The _links property is an object with HATEOAS links related to the object listing. The pagination property is an object with details about the result page count, total count, and pagination numbers.

Definition

GET https://voice.messagebird.com/numbers

Example request

curl -X GET "https://voice.messagebird.com/numbers?page=1" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "d212d28a-bfe7-1235-1abd-f01fafdf8755",
"number": "31123456789",
"callFlowId": "200d95ee-4fcf-46e7-b75a-32a26cb6ebf4",
"createdAt": "2019-11-11T14:53:47Z",
"updatedAt": "2020-07-30T14:30:11Z"
},
{
"id": "023746d4-4ba4-44eb-a619-ba50da3b16f1",
"number": "32460205634",
"callFlowId": "e7b768eb-df78-4271-8940-9ffb9149dae7",
"createdAt": "2018-10-24T16:12:03Z",
"updatedAt": "2019-02-05T14:38:19Z"
}
],
"_links": {
"self": "/numbers?page=1"
},
"pagination": {
"totalCount": 2,
"pageCount": 1,
"currentPage": 1,
"perPage": 10
}
}

Get webhooks for number

This request retrieves all the webhooks associated with the number (if any).

URI

https://voice.messagebird.com/numbers/{number}/webhook

Response

If successful, the request will return an object with a data and _links. If the request failed, an error object will be returned.

The data property is an array of webhook objects.

Definition

GET https://voice.messagebird.com/numbers/{number}/webhook

Example request

curl -X GET "https://voice.messagebird.com/numbers/{number}/webhook" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "5f3cf195-b9c2-40fb-b4a6-aad529115f8f",
"url": "https://example.com/343334",
"token": "foobar123",
"createdAt": "2020-08-03T22:50:14Z",
"updatedAt": "2020-08-03T22:50:14Z"
}
],
"_links": {
"self": "/numbers/3123XXXXXX/webhook"
}
}

Create webhook for number

This request creates a webhook and associates it with a purchased number if the number is purchased with the voice feature enabled. There is a limit of 5 webhooks allowed per number. Unused webhooks may be deleted via the delete webhook endpoint.

Parameters

ParameterTypeDescriptionRequired
urlstringURL to be used for the callbackYes
tokenstringToken for authorising the URLNo

URI

https://voice.messagebird.com/numbers/{number}/webhook

Response

If successful, the request will return an object with a data and _links. If the request failed, an error object will be returned. Duplicate webhooks are silently ignored and will appear as successful.

The data property is an array of webhook objects with only one object in it.

Definition

POST https://voice.messagebird.com/numbers/{number}/webhook

Example request

curl -X POST "https://voice.messagebird.com/numbers/{number}/webhook" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-H 'Content-Type: application/json' \
-d $'{
"url": "https://example.com/test",
"token": "foobar123"
}'

Example response

{
"data": [
{
"id": "a3105944-703d-413f-bb13-42027dbee2ab",
"url": "https://example.com/test",
"token": "foobar123",
"createdAt": "2020-08-04T00:31:10Z",
"updatedAt": "2020-08-04T00:31:10Z"
}
],
"_links": {
"self": "/webhooks/a3105944-703d-413f-bb13-42027dbee2ab"
}
}

Webhooks

Webhooks are a way of receiving event data for your calls and associated resources by your own servers.

Types of callback webhooks

There are three types of webhooks each with its own purpose.

Generic webhooks

These webhooks are account-wide webhooks and maintainable via the API endpoints described in the next section. They can be used to receive events from all your calls, both inbound and outbound without any extra configuration. You may create up to 5 generic webhooks for your user account.

Call webhooks

Call webhook is a short-lived webhook for outbound calls that can be passed with the create call request via the webhook object. If there is a call webhook set for an outbound call, that (and only that) will be used for all callbacks associated with the call so any generic webhooks will be ignored. Call webhooks only affect the call they are assigned to (including its legs), do not have any effect on other calls and will not appear in the API endpoints defined below.

Number webhooks

Number webhooks are webhooks for inbound calls associated with purchased numbers as described in the numbers section. They can be set once and assigned to one or multiple numbers and will trigger for all inbound calls without any other action needed. There is a limit of 5 number webhooks per number and that limit is seperate from the generic-webhook limit. They will appear in the API endpoints defined below for transparency but creation still needs to happen via the number endpoints.

Notification icon

Some number webhooks might be automatically set just by using our Flowbuilder product and these are critical for the operation of your Flowbuilder flows. For transparency these webhooks will also appear in the API endpoints below and it is advised not to alter nor delete them.

The webhook object

This object represents a configuration for delivering webhooks.

Attributes

AttributeTypeDescription
idstringThe unique ID of the webhook.
urlstringThe callback URL that will be requested when our platform sends a webhook.
tokenstringThe secret used for signing webhook requests. It's suggested to be of at least 32bytes long.
numberstring(Optional) The number shown in the case of number webhooks.
createdAtstringThe date-time when webhook was created, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).
updatedAtstringThe date-time when webhook was updated, in RFC 3339 format (e.g. 2017-03-06T13:34:14Z).

Webhook object example

{
"id": "534e1848-235f-482d-983d-e3e11a04f58a",
"url": "https://example.com/",
"token": "foobar",
"createdAt": "2017-03-15T14:10:07Z",
"updatedAt": "2017-03-15T14:10:07Z"
}

URI

https://voice.messagebird.com/webhooks

Available HTTP Methods

GET /webhooks/
GET /webhooks/{id}
POST /webhooks/
PUT /webhooks/{id}
DELETE /webhooks/{id}

List all webhooks

This request retrieves a listing of all webhooks.

Response

If successful, this request returns an object with a data, _links and pagination properties. If the request failed, an error object will be returned.

The data property is an array of webhook objects, can be null if there are no webhooks. The pagination property is an object with details about the result page count, total count, and pagination numbers.

Example request

curl -X GET "https://voice.messagebird.com/webhooks" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "534e1848-235f-482d-983d-e3e11a04f58a",
"url": "https://example.com/",
"token": "foobar",
"createdAt": "2017-03-15T13:28:32Z",
"updatedAt": "2017-03-15T13:28:32Z",
"_links": {
"self": "/webhooks/534e1848-235f-482d-983d-e3e11a04f58a"
}
}
],
"_links": {
"self": "/webhooks?page=1"
},
"pagination": {
"totalCount": 1,
"pageCount": 1,
"currentPage": 1,
"perPage": 10
}
}

Viewing a webhook

This request retrieves a webhook resource. The single parameter is the unique ID that was returned upon creation.

Required parameters

ParameterTypeDescriptionRequired
idstringThe unique ID which was returned upon creation of a webhook.Yes

Response

If successful, this request returns an object with a data property, which is an array that has a single webhook object. If the request failed, an error object will be returned.

Definition

GET https://voice.messagebird.com/webhooks/{id}

Example request

curl -X GET "https://voice.messagebird.com/webhooks/534e1848-235f-482d-983d-e3e11a04f58a" \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM"

Example response

{
"data": [
{
"id": "534e1848-235f-482d-983d-e3e11a04f58a",
"url": "https://example.com/",
"token": "foobar",
"createdAt": "2017-03-15T13:28:32Z",
"updatedAt": "2017-03-15T13:28:32Z"
}
],
"_links": {
"self": "/webhooks/534e1848-235f-482d-983d-e3e11a04f58a"
}
}

Creating a webhook

This request creates a new webhook. There is currently a limit of 5 (non-number) webhooks allowed per account and 5 per number.

Required parameters

ParameterTypeDescriptionRequired
urlstringThe URL to use for status callbacks. Setting a webhook URL when creating a call will override any webhook resource settings if they exist.Yes

Optional parameters

ParameterTypeDescriptionRequired
tokenstringThe secret used for signing webhook requests.No

Response

If successful, this request returns an object with a data property, which is an array that has a single webhook object. If the request failed, an error object will be returned. Duplicate webhooks are silently ignored and will appear as successful.

Definition

POST https://voice.messagebird.com/webhooks/

Example request

curl -X POST https://voice.messagebird.com/webhooks \
-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM" \
-H "Content-Type: application/json" \
-d $'{
"url": "https://example.com/",
"token": "foobar"
}'

Example response

{
"data": [
{
"id": "534e1848-235f-482d-983d-e3e11a04f58a",
"url": "https://example.com/",
"token": "foobar",
"createdAt": "2017-03-15T14:10:07Z",
"updatedAt": "2017-03-15T14:10:07Z"
}
],
"_links": {
"self": "/webhooks/534e1848-235f-482d-983d-e3e11a04f58a"
}
}

Updating a webhook

This request updates a webhook resource. The single parameter is the unique ID that was returned upon creation.

Required parameters

ParameterTypeDescriptionRequired
idstringThe unique ID that was returned upon creation of a webhook.Yes

Optional parameters

ParameterTypeDescriptionRequired
tokenstringThe secret used for signing webhook requests.No

Response

If successful, this request returns an object with a data property, which is an array that has a single webhook object. If the request failed, an error object will be returned.

Definition

PUT https://voice.messagebird.com/webhooks/{id}

Example request

curl -X PUT https://voice.messagebird.com/webhooks/534e1848-235f-482d-983d-e3e11a04f58a \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM' \
-d $'{
"url": "https://example.com/baz"
}'

Example response

{
"data": [
{
"id": "534e1848-235f-482d-983d-e3e11a04f58a",
"url": "https://example.com/baz",
"token": "foobar",
"createdAt": "2017-03-15T13:27:02Z",
"updatedAt": "2017-03-15T13:28:01Z"
}
],
"_links": {
"self": "/webhooks/534e1848-235f-482d-983d-e3e11a04f58a"
}
}

Deleting a webhook

This request deletes a webhook. The single parameter is the unique ID that was returned upon creation. This can also be used to delete webhooks for a number.

Required parameters

ParameterTypeDescriptionRequired
idstringThe unique ID that was returned upon creation of a webhook.Yes

Response

If successful, this request returns an HTTP header of 204 No Content and an empty response. If the request failed, an error object will be returned.

Definition

DELETE https://voice.messagebird.com/webhooks/{id}

Example request

curl -X DELETE https://voice.messagebird.com/webhooks/534e1848-235f-482d-983d-e3e11a04f58a \
-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0QyM'

Callbacks

Callbacks are HTTP requests sent to your platform when a call is created or updated. A callback is triggered by a webhook. To set up webhooks, please refer to the webhooks documentation.

Request

Each HTTP request has a body with a JSON object of the created/updated resource.

HTTP body

AttributeTypeDescription
timestampdatetimeThe date-time the callback was created, in RFC 3339 format (e.g. 2020-08-03T15:58:41.56831062Z).
itemsarrayAn array of items that triggered a callback. When sending callbacks, our platform might batch items, where each item will be an object in this array.
items[].typestringThe type of the resource that got created/updated. e.g. call, leg,transcription.
items[].eventstringThe event that triggered the callback. e.g. callCreated, callUpdated,amdComplete. Optional
items[].payloadobjectThe resource related to the event.

Callback events

Callbacks are sent for multiple types of events and the items in the callback body may vary per type. Web callbacks are currently supported for the following:

Event TypeEventsPayload
callcallCreated,callUpdatedcall
legleg
AMDCompleteEventamdCompleteamdComplete
recordingrecordingStarted,recordingUpdatedrecording
transcriptiontranscriptionCreated,transcriptionFinished,transcriptionTranscribingtranscription

Response

Your platform should respond with a 200 OK HTTP header.

Example request (Type call)

POST / HTTP/1.1
Host: example.com
Content-Type: application/json
X-MessageBird-Signature: roAnwpDfIzW6G3JpKVS6866CKHcJQUiAC9DqswzGY6s/xFPUIa5Qla9AZuCOSQ=
Content-Length: 760
{
"timestamp": "2017-08-30T07:56:46Z",
"items": [
{
"type": "call",
"event": "callUpdated",
"payload": {
"id": "5a0dfae6-c809-4f6f-9e3d-c593149e4c0f",
"status": "ended",
"source": "31644556677",
"destination": "31612345678",
"createdAt": "2017-08-30T07:54:22Z",
"updatedAt": "2017-08-30T07:56:46Z",
"endedAt": "2017-08-30T07:56:46Z",
}
}
]
}

Example request (Type leg)

POST / HTTP/1.1
Host: example.com
Content-Type: application/json
X-MessageBird-Signature: roAnwpDfIzW6G3JpKVS6866CKHcJQUiAC9DqswzGY6s/xFPUIa5Qla9AZuCOSQ=
Content-Length: 376
{
"timestamp": "2017-09-14T07:40:12Z",
"items": [
{
"type": "leg",
"payload": {
"id": "f3e699db-68a5-49dc-8f5b-e5272a7349c7",
"callId": "2452531a-b7a9-4797-a45e-20f5feaf46ce",
"source": "31644556677",
"destination": "31612345678",
"status": "ringing",
"direction": "outgoing",
"duration": 0,
"createdAt": "2017-09-14T07:40:07Z",
"updatedAt": "2017-09-14T07:40:07Z",
"answeredAt": null,
"endedAt": null
}
}
]
}

Example request (Type AMDCompleteEvent)

AMD events will mainly have a status and a cause.

The status can have the values: MACHINE,HUMAN,NOTSURE,HANGUP and the cause will give more information about the detection. e.g. INITIALSILENCE-2500-2500 if a machine was detected due to some unusual silence when starting the call.

POST / HTTP/1.1
Host: example.com
Accept-Encoding: gzip
Content-Type: application/json
Messagebird-Request-Timestamp: 1593666577
Messagebird-Signature: VasRR95LGHzM2DJ1tF/qaegtzUm8alUPVhiLNQoQjmQ=
User-Agent: MessageBirdHTTPQueue/1386
X-Messagebird-Request-Id: 3a13544c-bc22-11ea-a9a1-363c205f94d1
Content-Length: 817
Connection: keep-alive
{
"timestamp": "2020-07-02T05:09:37.745741202Z",
"items": [
{
"type": "AMDCompleteEvent",
"event": "amdComplete",
"payload": {
"Call": {
"id": "c95ac24f-10e7-48ad-aa03-2887727d03b0",
"status": "ongoing",
"source": "31644556677",
"destination": "31612345678",
"webhook": {
"url": "https://example.com"
},
"createdAt": "2020-07-02T05:09:29Z",
"updatedAt": "2020-07-02T05:09:33Z",
"endedAt": null
},
"Leg": {
"id": "46733c65-0865-4c53-9e65-f7a09f0ec588",
"callId": "c95ac24f-a0e7-48ad-aa03-2887727d03b0",
"source": "31207009850",
"destination": "31624973844",
"status": "ongoing",
"direction": "outgoing",
"duration": null,
"createdAt": "2020-07-02T05:09:29Z",
"updatedAt": "2020-07-02T05:09:37Z",
"answeredAt": "2020-07-02T05:09:33.183Z",
"endedAt": null
},
"Status": "MACHINE",
"Cause": "INITIALSILENCE-2500-2500",
"Timestamp": "2020-07-02T05:09:37.745741202Z"
}
}
]
}
Notification icon

It is suggested not to depend on the completeness of the data received in the callbacks as some fields' availability may vary depending on the type and state of call. For example legs will not always have a duration nor cost and some other fields like answeredAt might be null. For AMD events specifically the call and leg data might not be fully synchronised with the actual state of the call and is provided mainly matching with other call and leg data via the call and leg ID's.

Validation of signatures

Notification icon

Voice webhook/callback signature generation used in POST HTTP requests differs from both the signature generation used for fetching Dynamic call flows and the generic signature generation used by other MessageBird services

Each Webhook callback HTTP request is signed with a signature, a base64 encoded HMAC found in the X-MessageBird-Signature HTTP header. To ensure the callback is coming from the MessageBird platform, we strongly advise you to validate its signature by calculating the binary HMAC of the callback and base64 encoding it.

Using HMAC-SHA256, the HTTP body is the message and the token of the related webhook resource is the secret. Only handle the webhook if the computed value matches the signature in the HTTP header.

Signature simulation example

# Emulate the X-Messagebird-Signature generation from the command line using openssl and base64.
$ echo -n 'callID=97f9b1d2-b8b4-4db7-8829-ec3e660d2cdb&destination=19027064857&firstLegDirection=incoming&source=%2B31611171210&variables=%7B%22testingvar%22%3A%222%22%7D'| openssl dgst -sha256 -hmac "some-custom-token" -binary |base64
v3HpIXiFBDvwiwA4wwgRg6T85Vs7o74w8wAvkOoyDo8=

Pseudocode example

signature = HMAC_SHA_256(
SHA_256_SUM(BODY),
signing_key
)
if HMAC_EQUALS(signature, BASE_64_DECODE(request_signature)) {
// Yay!
}

Allowed Caller IDs

Only phone numbers which are owned or verified can be used as a caller ID.

An owned number is a MessageBird-hosted number that you bought via your account.

A verified number is non-MessageBird-hosted number which is verified in your account. You can find more about verified numbers in the article.

Questions?

We’re always happy to help with code or other doubts you might have! Check out our Quickstarts, API Reference, Tutorials, SDKs, or contact our Support team.

Cookie Settings