This method allows adding new contacts to WAMM.chat or updating information about existing contacts. Useful for synchronizing contact databases between different systems, automatically updating customer data from CRM, and adding new customers before sending them messages. Adding a contact does not require prior verification of its existence in the system.
GET /api2/contact_to/{token}/?phone={phone}&name={name}&info={info}&email={email}&web={web} Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | string | Yes | API token obtained in the settings |
| phone | string | Yes | Phone number in international format (e.g., 79001234567) or chat ID for Telegram |
| name | string | Yes | Contact name |
| info | string | No | Note or remark for the contact |
| string | No | Contact email | |
| web | string | No | Contact's website or page URL |
Success Response
{"err":0,"result":"insert"} or
{"err":0,"result":"update"} Possible Errors
| Error Code | Description |
|---|---|
| token fail | Token error |
| acc not authorized | Connection not authorized |
| phone fail | Phone number error |
| no WhatsApp on the number | No WhatsApp with this number |
| no Account on the number | No account with this number for other channels (Telegram...) |
| phone not checked for WhatsApp, please retry | Number not checked for WhatsApp presence |
| phone not checked, please retry | Number not checked for account presence for other channels |
| name fail | Name not specified |
| name fail, more 250 | Name too large, exceeds 250 characters |
| web fail, more 150 | URL too large, exceeds 150 characters |
| email fail, more 150 | Email too large, exceeds 150 characters |
Usage Examples
curl -X GET "https://wamm.chat/api2/contact_to/YOUR_TOKEN/?phone=79001234567&name=Ivan%20Petrov&info=New%20client&email=ivan@example.com&web=https://example.com" function addOrUpdateContact($token, $phone, $name, $info = '', $email = '', $web = '') {
// Prepare the request URL
$url = "https://wamm.chat/api2/contact_to/$token/?phone=" . urlencode($phone) .
"&name=" . urlencode($name);
// Add optional parameters if specified
if (!empty($info)) {
$url .= "&info=" . urlencode($info);
}
if (!empty($email)) {
$url .= "&email=" . urlencode($email);
}
if (!empty($web)) {
$url .= "&web=" . urlencode($web);
}
// Execute the request
$response = file_get_contents($url);
// Process the response
if ($response !== false) {
// Convert the response to an array
$json_response = json_decode($response, true);
// Check for errors
if (isset($json_response['err'])) {
if ($json_response['err'] == 0 && isset($json_response['result'])) {
if ($json_response['result'] === 'insert') {
echo "Contact successfully added";
} else if ($json_response['result'] === 'update') {
echo "Contact successfully updated";
}
return true;
} else {
echo "Error: " . $json_response['err'];
}
} else {
echo "Failed to process server response";
}
} else {
echo "Failed to execute request to server";
}
return false;
}
// Use the function to add or update a contact
$token = "YOUR_TOKEN";
$phone = "79001234567";
$name = "Ivan Petrov";
$info = "New client";
$email = "ivan@example.com";
$web = "https://example.com";
addOrUpdateContact($token, $phone, $name, $info, $email, $web);