POST/ message/ send_message_as_user/
Send message as user
Send messages on chat on behalf of your users. Depending on your needs, you can create new conversations for your users or add messages to the existing conversations. In case of mismatching user_id with conversation id, the message won't be sent and a proper response will appear.
Attributes
Optional unless marked required
- conversation
- A unique identifier for the conversation which is given by User (when conversation id is not provided - the request will create new converstaion for the user specified by user_id or user_custom_id).
* conversation is required if in the same payload "state" key is used. - user_id
- A unique identifier for the user which is given by User automatically.
- user_custom_id
- The unique identifier for the user which is provided by the client.
- content
- Content of a message.
- state
- Conversation status. You can choose between: 'snoozed', 'close' and 'active'.
- snoozed_to
- Required if the 'snoozed' state is chosen.
- source
- Where the message was sent from:
1chat,2email,3API (the default),4SMS,8Facebook,9Instagram,10ChatAI. See Message source types.
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/message/send_message_as_user/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"conversation": 12345,
"user_id": 12345,
"content": "Thanks, that helps!"
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/message/send_message_as_user/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
conversation: 12345,
user_id: 12345,
content: "Thanks, that helps!",
}),
},
);
const data = await response.json();
console.log(data);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://<your_app_subdomain>.user.com/api/public/message/send_message_as_user/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Token <your_64_char_api_key>",
"Accept: */*; version=2",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"conversation" => 12345,
"user_id" => 12345,
"content" => "Thanks, that helps!",
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/message/send_message_as_user/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"conversation": 12345,
"user_id": 12345,
"content": "Thanks, that helps!",
},
)
print(response.json())
Response examples
- 201 Created
- 400 Bad Request
{"id": 1,"assigned_to": {"id": 1,"key": "g7lvoickax9e","name": "Jane Agent","email": "agent@example.com"},"active": true,"agent": {"id": 1,"name": "Jane Agent"},"messages": 1}{"content": ["This field is required."]}Response fields
Fields returned in the 201 Created response body.
- id
- A unique identifier for the conversation which is given by User automatically.
- assigned_to
- A unique identifier for the agent which is given by User automatically.
- assigned_to.
id - A unique identifier for the conversation which is given by User automatically.
- assigned_to.
key - The contact's
user_key: a 12-character identifier assigned by User. - assigned_to.
name - The contact's name.
- assigned_to.
email - The contact's email address, or
nullif they have none.
- assigned_to.
- active
- Whether the conversation is open.
falseonce it is closed. - agent
- The agent group the conversation is assigned to, or
null.- agent.
id - A unique identifier for the conversation which is given by User automatically.
- agent.
name - Name of the agent group.
- agent.
- messages
- Number of messages in the conversation.
note
Errors that can come from any endpoint (401, 429, 500, 502, 504) are described in HTTP response codes.