This method allows you to retrieve a list of all open (active) chats or chats of a specific user by their user_id. It is useful for monitoring operator workload, analyzing chat distribution within a team, and for automatic load redistribution among employees. It can also be used for analytics of support and sales departments. If you have multiple channels, regardless of which channel's token is used for the request, information for all users is displayed.

You may need a request to get a list of users and their user_id.


Request Example:

GET https://wamm.chat/api2/user_chats/{token}/{user_id}/{filter_by_channel}

Request Parameters
ParameterTypeRequiredDescription
tokenstringYesAPI token obtained from settings
user_idintegerNoID of the user whose open chats need to be retrieved. Or omit the ID (or use - 0) to get all open chats (but no more than 900)
filter_by_channelintegerNoReturns only chats of the current channel (1) or all channels (0 or omit)

Success Response
{
    "err": 0,
    "data": [
        {
            "chat_id": "1xxx",
            "chat_name": "Name chat",
            "phone": "7xxx",
            "avatar": "https...jpg",
            "user_id": "8xxx",
            "date_msg": "2024-10-09 10:28:45",
            "api_id": "1xxx",
        },
        ...
    ]
}

Response Field Descriptions
FieldDescription
chat_idChat identifier
chat_nameChat or contact name
phonePhone number or chat ID
avatarAvatar URL
user_idID of the user responsible for the chat
date_msgDate and time of the last message in the chat
api_idChannel number

Possible Errors
Error CodeDescription
token failToken error
acc not authorizedConnection not authorized
user_id failUser not found for the specified user_id
fail get dataUser chats not found

Usage Examples
curl -X GET "https://wamm.chat/api2/user_chats/YOUR_TOKEN/123"
function getUserChats($token, $userId) {
    // Prepare the request URL
    $url = "https://wamm.chat/api2/user_chats/$token/$userId";

    // 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['data'])) {
                echo "User chat list successfully retrieved. Number of chats: " . count($json_response['data']);
                return $json_response['data'];
            } else {
                echo "Error: " . $json_response['err'];
            }
        } else {
            echo "Failed to process the server response";
        }
    } else {
        echo "Failed to execute the request to the server";
    }

    return [];
}

// Use the function to get user chats
$token = "YOUR_TOKEN";
$userId = 123;

$userChats = getUserChats($token, $userId);
foreach ($userChats as $chat) {
    echo "Chat: " . $chat['chat_name'] . ", Last message: " . $chat['date_msg'] . "\n";
}