Create a contact in your directory
This endpoint will let you create a contact into your 2Chat account.
Contact fields
Each contact must have at least a first name and some contact details like a phone number or an email address.
Field | Description |
---|---|
first_name | First name |
last_name | Last name |
profile_pic_url | A publicly accessible URL |
contact_details | A list of contact details |
Contact details
Each person in your contact directory can have many associated details, like a phone number or a physical address. You can specify which information type you are creating by selecting the right type for each value following the instructions on the table below:
Type | Description | Example values |
---|---|---|
E | Email address | myemail@example.com |
A | Physical address | Flower St. 123 |
PH | Phone number | +12121112222 |
WAPH | Phone number that has a WhatsApp account | +12121112222 |
caution
When specifying a phone number, always use its international format.
Invocation
- cURL
- Python
- NodeJS
curl --location --request POST 'https://api.p.2chat.io/open/contacts' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here' \
--data '{
"first_name": "2Chat",
"last_name": "Support",
"contact_detail": [
{ "type": "PH", "value": "+17137157533" },
{ "type": "WAPH", "value": "+17137157533" },
{ "type": "E", "value": "support@2chat.co" }
]
}'
import requests
import json
url = "https://api.p.2chat.io/open/contacts"
payload = json.dumps(
{
"first_name": "2Chat",
"last_name": "Support",
"contact_detail": [
{ "type": "PH", "value": "+17137157533" },
{ "type": "WAPH", "value": "+17137157533" },
{ "type": "E", "value": "support@2chat.co" }
]
}
)
headers = {
'X-User-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
var axios = require('axios');
var data = JSON.stringify({
"first_name": "2Chat",
"last_name": "Support",
"contact_detail": [
{ "type": "PH", "value": "+17137157533" },
{ "type": "WAPH", "value": "+17137157533" },
{ "type": "E", "value": "support@2chat.co" }
]
});
var config = {
method: 'post',
url: 'https://api.p.2chat.io/open/contacts',
headers: {
'X-User-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Response
The API will response with the new contact it created if the invocation succeeded.
{
"success": true,
"contact": {
"uuid": "CON2226e836-36dc-4103-b2a2-6307749cf390",
"first_name": "2Chat",
"last_name": "Support",
"channel_uuid": null,
"profile_pic_url": null,
"details": [
{
"id": 1331,
"value": "+17137157533",
"type": "PH",
"created_at": 1695230471,
"updated_at": 0
},
{
"id": 1332,
"value": "+17137157533",
"type": "WAPH",
"created_at": 1695230471,
"updated_at": 0
},
{
"id": 1333,
"value": "support@2chat.co",
"type": "E",
"created_at": 1695230471,
"updated_at": 0
}
]
}
}