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
ParameterTypeRequiredDescription
tokenstringYesAPI token obtained in the settings
phonestringYesPhone number in international format (e.g., 79001234567) or chat ID for Telegram
namestringYesContact name
infostringNoNote or remark for the contact
emailstringNoContact email
webstringNoContact's website or page URL
Success Response
{"err":0,"result":"insert"}

or

{"err":0,"result":"update"}

Possible Errors
Error CodeDescription
token failToken error
acc not authorizedConnection not authorized
phone failPhone number error
no WhatsApp on the numberNo WhatsApp with this number
no Account on the numberNo account with this number for other channels (Telegram...)
phone not checked for WhatsApp, please retryNumber not checked for WhatsApp presence
phone not checked, please retryNumber not checked for account presence for other channels
name failName not specified
name fail, more 250Name too large, exceeds 250 characters
web fail, more 150URL too large, exceeds 150 characters
email fail, more 150Email 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);