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 | Type | Required | Description |
|---|---|---|---|
| user_id | integer | yes | A unique identifier for the user which is given by User.com automatically. |
| user | integer | no | A unique identifier for the agent (an author of the message) which is given by User.com automatically. |
| content | string | yes | A content of a message sent to the user. |
| source | integer | no | A source of your message (1 - chat, 2 - email, 3 - API, 4 - SMS, 5 - Slack). |
| source_context | string | no | An additional context for your source (only visible for you). |
Request
- CURL
- JavaScript
- PHP
- Python
curl -X POST -H "Authorization: Token <your_64_char_api_key>"
-H "Accept: */*; version=2" -H "Content-Type: application/json" -d '{
"content": "Message sent using API",
"user": 926,
"source": 2,
"source_context": {
"name": "This is source_context used in API",
"id": 123
}
}' "https://<your_app_subdomain>.user.com/api/public/users/:user_id/conversations/"
var data = JSON.stringify({
"content": "Message sent using API",
"user": 1,
"source": 2,
"source_context": {
"name": "This is source_context used in API",
"id": 123
}
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://<your_app_subdomain>.user.com/api/public/users/:user_id/conversations/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("accept", "*/*; version=2");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
<?php
$request = new HttpRequest();
$request->setUrl('https://<your_app_subdomain>.user.com/api/public/users/:user_id/conversations/');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array(
'content-type' => 'application/json',
'authorization' => 'Token <your_64_char_api_key>'
));
$request->setBody('{
"content": "Message sent using API",
"user": 926,
"source": 2,
"source_context": {
"name": "This is source_context used in API",
"id": 123
}
}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
import http.client
conn = http.client.HTTPSConnection("/<your_app_subdomain>.user.com")
payload = "{\n \"content\": \"Message sent using API\",\n \"user\": 926,\n \"source\": 2,\n \"source_context\": {\n \t\"name\": \"This is source_context used in API\",\n \t\"id\": 123\n }\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'Accept': "*/*; version=2",
'content-type': "application/json"
}
conn.request("POST", "/api/public/users/:user_id/conversations/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Response
{
"id":89,
"user": {
"id":322842,
"key":"2if9jlgsfsw3",
"name":"John Doe",
"email":"johndoe@response.example"},
"active":true,
"agent":null,
"messages":1
}