Create a contact in your directory
This endpoint will let you create a contact in your 2Chat account and WhatsApp account, when specified.
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 |
channel_uuid | When provided, the contact will also be created on your WhatsApp account |
contact_details | A list of contact details |
The channel_uuid parameter must a WhatsApp channel. When provided, the contact will be created on your 2Chat account and also on the WhatsApp account associated to this channel. If the contact exists on your WhatsApp account, it will be updated.
You can obtain a list of UUIDs using the list numbers endpoint.
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 |
When specifying a phone number, always use its international format.
Invocation
- cURL
- Python
- JavaScript
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",
"channel_uuid": "WPN66037eca-9ad1-4c96-9eff-526a90a48c77",
"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",
"channel_uuid": "WPN66037eca-9ad1-4c96-9eff-526a90a48c77",
"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",
"channel_uuid": "WPN66037eca-9ad1-4c96-9eff-526a90a48c77",
"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": "WPN66037eca-9ad1-4c96-9eff-526a90a48c77",
"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
}
]
}
}