MessageBird’s Contacts API (V2) allows you to create and manage a single omni-channel profile for any customer you message on any of MessageBird’s supported platforms. This means that regardless of which platform a customer is messaging you on, you will always be able to identify who they are. Contacts API V2 is available for all customers using Programmable Conversations to message their customers over Facebook Messenger, LINE, Telegram, WeChat, SMS, and WhatsApp.
https://contacts.messagebird.com/v2
// ContactsGET /contactsPOST /contactsGET /contacts/{id}PATCH /contacts/{id}DELETE /contacts/{id}// IdentifiersPOST /contacts/{id}/identifiersDELETE /contacts/{id}/identifiers/{id}// ImportsPOST /import/contactsGET /import/contacts/{import_id}/status
With each API call you'll need to set an access key to authenticate yourself. API keys can be created or retrieved through the MessageBird Dashboard.
To provide the access key, set the Authorization header in the form of AccessKey {accessKey}.
All API responses are in JSON. You're required to send the Accept header with the value application/json with each request.
POST and PUT requests to the API must contain a JSON-formatted payload in the request body.
MessageBird uses standard HTTP status codes to indicate success or failure of an API request. 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 the case of an error, the body of the response includes a JSON-formatted response that tells you exactly what is wrong.
Attribute | Type | Description |
---|---|---|
errors[].code | integer | An integer that represents the error type. |
errors[].description | string | A human-readable description of the error. You can use this to let the user know what they can do about the error. |
errors[].parameter | string | The parameter in your request related to the error if the error is parameter specific. |
A Contact represents an end-user or customer that you have been in touch with on a messaging platform. A single contact might be present across multiple platforms, e.g. you might have a customer "Jane Doe" and she can be reached on SMS, WhatsApp, and Telegram because she has reached out to your business across all of these platforms. Jane can exist as a single contact in the Contacts API to make repeated communication seamless, regardless of what platform you're talking over.
Attribute | Type | Description |
---|---|---|
id | string | A unique random ID which is created on the MessageBird platform and is returned upon creation of the contact. |
displayName | string | A display name (e.g. "{firstName} {lastName}", a username, or phone number) for the contact, typically used when displaying a contact in UI. |
firstName | string | Optional. The first name of the contact. |
lastName | string | Optional. The last name of the contact. |
languages | Array | Optional. An array of language identifiers. Will be populated with ISO 639-1 codes for the language of this contact if the contact has messaged on a platform that provides locale data. |
country | string | Optional. An identifier the country this contact resides in. Will be populated with an ISO 3166-1 code if the contact has messaged on a platform that provides country data. |
avatar | string | Optional. A URL linking to an avatar for this contact. |
gender | string | Optional. A gender identifier for the customer. Free text format. |
status | string | The status of this contact, one of: active, merged. |
profiles | Array of Profile | Optional. An array of the profiles that link this Contact to a specific channel. |
attributes | JSON | Optional. Custom key-value attributes that can be assigned to the contact. Any valid JSON object is accepted, but the maximum size of the object is 10kB. |
href | string | The URL for this contact resource. |
createdAt | date | RFC3339 formatted timestamp of the creation time of the contact. |
updatedAt | date | RFC3339 formatted timestamp of the time of the last update made to the contact. |
{"id": "f4a4af42f9894b56b6f7b3418443b2e1","href": "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1","displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","identifiers": [{"id": "d4095cbec4be475c862f329b109e961e","type": "emailaddress","value": "jane.tester@messagebird.com"},{"id": "5abffd64e6aa445fa9947449e44c49f0","type": "phonenumber","value": "3112345678"}],"languages": ["en","nl"],"timezone": "UTC+1","country": "NL","avatar": "https://example.com/avatar.png","gender": "f","profiles": [{"id": "de93f56a2d7442d3b1e9048637c7382e","channelId": "d759a993508e42e49fa74afc0687cc4b","identifier": "3112345678"}],"attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"},"status": "active","createdAt": "2019-05-08T12:23:19Z","updatedAt": "2019-05-08T12:23:19Z"}
An Identifier is a value used by other platforms to Identify a contact. This can be a generic identifier such as a phone number or email address that are used with multiple platforms, as well as some platform specific identifiers such as your Facebook ID.
Attribute | Type | Description |
---|---|---|
id | string | A unique random ID used to identify this identifier on the MessageBird platform. |
type | string | The type of identifier. |
value | string | The identifier of the user on the provided channel. |
Here is a list of possible identifier types. This list will expand as we add new channels.
Type | Description |
---|---|
phonenumber | A valid MSISDN used by channels like WhatsApp and SMS. |
emailaddress | Email Address used by channels identifying with email. |
Facebook user ID, Can only be used with the Facebook channel. | |
WeChat user ID. Can only be used with the WeChat channel. | |
line | Line user ID. Can only be used with the Line channel. |
telegram | Telegram user ID. Can only be used with the Telegram channel. |
Instagram user ID. Can only be used with the Instagram channel. | |
Twitter user ID. Can only be used with the Twitter channel. |
The Profile object is a link between your contact on MessageBird and one of your configured messaging channels, e.g. a Facebook page, Telegram bot, or WhatsApp Business Account. Identifiers depend on the platform, for example, a WhatsApp channel identifier is an MSISDN registered to a user's account on WhatsApp, a Facebook identifier is a page-scoped ID value provided by Facebook.
There is no limit to the number of profiles a contact can have. Some platforms, such as Facebook Messenger, have a different user identifier per page. This means your contact can have a profile for each configured channel even if some of those channels belong to the same platform.
Attribute | Type | Description |
---|---|---|
id | string | A unique random ID used to identify this profile on the MessageBird platform. |
channelId | string | The id of the MessageBird channel for this profile. |
identifier | string | The platform-specific identifier of the user on the provided channel. |
Retrieves all contacts for this account. By default, contacts are sorted by the createdAt field so that all new contacts appear first.
No parameters are required; however, filters and pagination can be provided through the following optional query parameters:
Parameter | Type | Description | Example |
---|---|---|---|
ids | string | Comma separated list of contact ids to filter. | ids=idA,idB,idC |
channelId | string | Only return contacts that have a profile associated with this channel. | channelId=2ccb501a4b0e440a8779103478292f84 |
identifierExact | string | Only return contacts with this Identifier associated to the contact. | identifierExact=jane.tester@messagebird.com |
status | string | Contact status. active or merged. Default: active. | status=active |
limit | integer | The number of maximum objects to return on each request. Default: 20 | limit=10 |
offset | integer | The number of objects to skip from the first. Default: 0 | offset=120 |
GET https://contacts.messagebird.com/v2/contacts
curl "https://contacts.messagebird.com/v2/contacts?channelId=d759a993508e42e49fa74afc0687cc4b&status=active&offset=40&limit=10" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8'
{"totalCount": 43,"count": 3,"offset": 10,"limit": 10,"items": [{"id": "f4a4af42f9894b56b6f7b3418443b2e1","href": "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1","displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","identifiers": [{"id": "d4095cbec4be475c862f329b109e961e","type": "emailaddress","value": "jane.tester@messagebird.com"},{"id": "5abffd64e6aa445fa9947449e44c49f0","type": "phonenumber","value": "3112345678"}],"languages": ["en","nl"],"timezone": "UTC+1","country": "NL","avatar": "https://example.com/avatar.png","gender": "f","profiles": [{"id": "de93f56a2d7442d3b1e9048637c7382e","channelId": "d759a993508e42e49fa74afc0687cc4b","identifier": "3112345678"}],"attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"},"status": "active","createdAt": "2019-05-08T12:23:19Z","updatedAt": "2019-05-08T12:23:19Z"},{"...": "..."},{"...": "..."}]}
POST https://contacts.messagebird.com/v2/contacts
curl -X POST "https://contacts.messagebird.com/v2/contacts" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","avatar": "https://example.com/avatar.png","languages": ["en","nl"],"country": "NL","timezone": "UTC+1","gender": "f","attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"}}'
{"id": "f4a4af42f9894b56b6f7b3418443b2e1","href": "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1","displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","identifiers": [{"id": "d4095cbec4be475c862f329b109e961e","type": "emailaddress","value": "jane.tester@messagebird.com"},{"id": "5abffd64e6aa445fa9947449e44c49f0","type": "phonenumber","value": "3112345678"}],"languages": ["en","nl"],"timezone": "UTC+1","country": "NL","avatar": "https://example.com/avatar.png","gender": "f","profiles": [],"attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"},"status": "active","createdAt": "2019-05-08T12:23:19Z","updatedAt": "2019-05-08T12:23:19Z"}
{"id": "f4a4af42f9894b56b6f7b3418443b2e1","href": "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1","displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","identifiers": [{"id": "d4095cbec4be475c862f329b109e961e","type": "emailaddress","value": "jane.tester@messagebird.com"},{"id": "5abffd64e6aa445fa9947449e44c49f0","type": "phonenumber","value": "3112345678"}],"languages": ["en","nl"],"timezone": "UTC+1","country": "NL","avatar": "https://example.com/avatar.png","gender": "f","profiles": [{"id": "de93f56a2d7442d3b1e9048637c7382e","channelId": "d759a993508e42e49fa74afc0687cc4b","identifier": "3112345678"}],"attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"},"status": "active","createdAt": "2019-05-08T12:23:19Z","updatedAt": "2019-05-08T12:23:19Z"}
Update properties of an existing contact by id. As this is a PATCH request, only fields that require changes need to be provided in the request.
The languages array field will be updated by replacing the entire array with what is provided in the request.
The attributes field will be updated as an RFC7386 merge patch. Existing attributes will be merged with new attributes provided in the patch request. If a key exists in the existing attributes and the patched attributes, it will be overwritten with the value from the patched attributes. Deleting an attribute is possible by setting it's value to null in the patch request.
PATCH https://contacts.messagebird.com/v2/contacts/{id}
curl -X PATCH "https://contacts.messagebird.com/v2/contacts/0b0f86191edb46cbb47c108f2c11d5a6" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"displayName": "Jane from MessageBird","languages": ["en", "fr"],"attributes": {"company": "MessageBird","team": "Product Engineering"}}'
{"id": "f4a4af42f9894b56b6f7b3418443b2e1","href": "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1","displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","identifiers": [{"id": "d4095cbec4be475c862f329b109e961e","type": "emailaddress","value": "jane.tester@messagebird.com"},{"id": "5abffd64e6aa445fa9947449e44c49f0","type": "phonenumber","value": "3112345678"}],"languages": ["en","nl"],"timezone": "UTC+1","country": "NL","avatar": "https://example.com/avatar.png","gender": "f","profiles": [{"id": "de93f56a2d7442d3b1e9048637c7382e","channelId": "d759a993508e42e49fa74afc0687cc4b","identifier": "3112345678"}],"attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"},"status": "active","createdAt": "2019-05-08T12:23:19Z","updatedAt": "2019-05-08T12:23:19Z"}
This method looks for an existing contact with passed identifiers and updates it with new ones from the request. If contact with such identifiers does not exist, it will create one. It returns updated or created contact ID and a flag that indicates if a contact was created. If updateContact argument set to false, contact fields will not be updated if the contact already exists. Pass false if you are unsure.
Use it if you don't know if a contact exists, otherwise use PATCH contact.
Attribute | Type | Description |
---|---|---|
updateContact | boolean | Weather to update contact if exists or not |
contact.id | string | A unique random ID which is created on the MessageBird platform and is returned upon creation of the contact. |
contact.displayName | string | A display name (e.g. "{firstName} {lastName}", a username, or phone number) for the contact, typically used when displaying a contact in UI. |
contact.firstName | string | Optional. The first name of the contact. |
contact.lastName | string | Optional. The last name of the contact. |
contact.email | string | DEPRECATED (Use Identifiers instead). The primary registered email address for this contact. |
contact.phone | string | DEPRECATED (Use Identifiers instead). The primary registered phone number for this contact. |
contact.languages | Array | Optional. An array of language identifiers. Will be populated with ISO 639-1 codes for the language of this contact if the contact has messaged on a platform that provides locale data. |
contact.country | string | Optional. An identifier the country this contact resides in. Will be populated with an ISO 3166-1 code if the contact has messaged on a platform that provides country data. |
contact.avatar | string | Optional. A URL linking to an avatar for this contact. |
contact.gender | string | Optional. A gender identifier for the customer. Free text format. |
contact.status | string | The status of this contact, one of: active, merged. |
contact.profiles | Array of Profile | Optional. An array of the profiles that link this Contact to a specific channel. |
contact.identifiers | Array of Identifier | Optional. An array of the identifiers that link this Contact. |
contact.attributes | JSON | Optional. Custom key-value attributes that can be assigned to the contact. Any valid JSON object is accepted, but the maximum size of the object is 10kB. |
contact.href | string | The URL for this contact resource. |
contact.createdAt | date | RFC3339 formatted timestamp of the creation time of the contact. |
contact.updatedAt | date | RFC3339 formatted timestamp of the time of the last update made to the contact. |
POST https://contacts.messagebird.com/v2/ops/contacts/upsert
curl -X POST "https://contacts.messagebird.com/v2/ops/contacts/upsert" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"updateContact": true,"contact": {"displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","avatar": "https://example.com/avatar.png","languages": ["en","nl"],"country": "NL","timezone": "UTC+1","gender": "f","attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"}}}'
Deletes a contact and its profiles. You only need to supply the unique id that was returned upon creation.
This request will hard delete the all conversations and conversation's messages that belongs to the contact ID.
Parameter | Type | Description |
---|---|---|
id | string | A unique random ID which is created on the MessageBird platform and is returned upon creation of the object. Required |
Returns an HTTP header of 204 No Content and an empty response if the request was successful. If the request failed, an error object will be returned.
Merge contact into another contact. It can be used to combine data from two different contacts, which should represent the same user. The one that's passed in the URL will be the active one.
Note that if merged contact had active conversations, they will be merged as well.
Attribute | Type | Description |
---|---|---|
origin | string | A unique random ID of the original contact. Required |
destination | string | A unique random ID of the destination contact. Required |
POST https://contacts.messagebird.com/v2/ops/contacts/merge
curl -X POST "https://contacts.messagebird.com/v2/ops/contacts/merge" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"origin": "5ff77bdc2f004451986be7e03894d52b","destination": "f4a4af42f9894b56b6f7b3418443b2e1"
{"id": "f4a4af42f9894b56b6f7b3418443b2e1","href": "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1","displayName": "Jane Tester","firstName": "Jane","lastName": "Tester","identifiers": [{"id": "d4095cbec4be475c862f329b109e961e","type": "emailaddress","value": "jane.tester@messagebird.com"},{"id": "5abffd64e6aa445fa9947449e44c49f0","type": "phonenumber","value": "3112345678"}],"languages": ["en","nl"],"timezone": "UTC+1","country": "NL","avatar": "https://example.com/avatar.png","gender": "f","profiles": [{"id": "de93f56a2d7442d3b1e9048637c7382e","channelId": "d759a993508e42e49fa74afc0687cc4b","identifier": "3112345678"}],"attributes": {"membership": "platinum","status": "vip","customerNumber": "1234"},"status": "active","createdAt": "2019-05-08T12:23:19Z","updatedAt": "2019-05-08T12:23:19Z"}
GET https://contacts.messagebird.com/v2/contacts/{id}/identifiers
curl "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1/identifiers" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8'
GET https://contacts.messagebird.com/v2/contacts/{id}/identifiers/{identifier_id}
curl "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1/identifiers/35964e692de14a8ca79ef0facb8d6c28" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8'
Link a identifier of a provided type to an existing Contact. Use this endpoint to add any known identifiers to a contact (such as email, phone, etc.).
POST https://contacts.messagebird.com/v2/contacts/{id}/identifiers
curl -X POST "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1/identifiers" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8' \-d $'{"type": "emailaddress","value": "mark@gmail.com"}'
DELETE https://contacts.messagebird.com/v2/contacts/{id}/identifiers/{identifier_id}
curl -X DELETE "https://contacts.messagebird.com/v2/contacts/f4a4af42f9894b56b6f7b3418443b2e1/identifiers/35964e692de14a8ca79ef0facb8d6c28" \-H 'Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy' \-H 'Content-Type: application/json; charset=utf-8'
This endpoint allows you to upload up to 100k of contacts in a csv file format. The required structure of a file is shown below. When you’re uploading a csv file, keep in mind that the headers must be set according to the headers fields below.
Header | Type | Description |
---|---|---|
phone | string | Optional. The primary registered phone number for this contact. |
string | Optional. The primary registered email address for this contact. | |
firstName | string | Optional. The first name of the contact. |
lastName | string | Optional. The last name of the contact. |
displayName | string | A display name (e.g. "{firstName} {lastName}", a username, or phone number) for the contact, typically used when displaying a contact in UI. |
custom:key | string | Any custom attributes you want to include in the contact, where key is a unique key in the contacts Attribute object. Eg: custom:account_id |
POST https://contacts.messagebird.com/v2/import/contacts
curl -X POST https://contacts.messagebird.com/v2/import/contacts \-H "Authorization: AccessKey test_gshuPaZoeEG6ovbc8M79w0Qy" \-H 'Content-Type: text/csv' \-H 'Content-Disposition: form-data; name="contacts"; filename="contacts.csv"' \-d '@test.csv'
phone,email,firstName,lastName,displayName,custom:membership,custom:status,custom:customerNumber+31612345678,johandoe@messagebird.com,John,Doe,John Doe,silver,,1111+3112345678,,Jane,Tester,Jane Tester,platinum,vip,1234
If the request is successful, it will return 200—this means the id exists; the response body will be as below. If the request fails, it means that the id could not be found.
Attributes | Type | Description |
---|---|---|
status | string | Status of the tracking. It can be completed, failed, queued or in progress |
message | string | Describing the status of importing the file |