POST/ users/ :user_id/ conversations/
Create conversation
You can create a conversation with your user starting with a message. Message content can be just plain text or HTML.
Hi
<b>user</b>, enjoy our product!
The message will be shown as follow:
Hi user, enjoy our product!
Attributes
Optional unless marked required
- user_id
- A unique identifier for the user which is given by User automatically.
- user
- A unique identifier for the agent (an author of the message) which is given by User automatically.
- content
- A content of a message sent to the user.
- source
- Where the message was sent from:
1chat,2email,3API (the default),4SMS,8Facebook,9Instagram,10ChatAI. See Message source types. - source_context
- An additional context for your source (only visible for you).
Request
- cURL
- JavaScript
- PHP
- Python
curl -X POST "https://<your_app_subdomain>.user.com/api/public/users/:user_id/conversations/" \
-H "Authorization: Token <your_64_char_api_key>" \
-H "Accept: */*; version=2" \
-H "Content-Type: application/json" \
-d '{
"content": "Hi! This is a test message from the API docs check.",
"source": 3,
"user": 2
}'
const response = await fetch(
"https://<your_app_subdomain>.user.com/api/public/users/:user_id/conversations/",
{
method: "POST",
headers: {
Authorization: "Token <your_64_char_api_key>",
Accept: "*/*; version=2",
"Content-Type": "application/json",
},
body: JSON.stringify({
content: "Hi! This is a test message from the API docs check.",
source: 3,
user: 2,
}),
},
);
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/users/:user_id/conversations/",
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([
"content" => "Hi! This is a test message from the API docs check.",
"source" => 3,
"user" => 2,
]),
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
response = requests.post(
"https://<your_app_subdomain>.user.com/api/public/users/:user_id/conversations/",
headers={
"Authorization": "Token <your_64_char_api_key>",
"Accept": "*/*; version=2",
},
json={
"content": "Hi! This is a test message from the API docs check.",
"source": 3,
"user": 2,
},
)
print(response.json())
Response examples
- 200 OK
- 404 Not Found
{"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}{
"detail": "No ClientUser matches the given query."
}
Response fields
Fields returned in the 200 OK response body.
- id
- A unique identifier for the conversation which is given by User automatically.
- assigned_to
- The contact the conversation is with.
- assigned_to.
id - ID of the contact.
- 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 - ID of the agent group.
- 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.