Create message


Send a conversation message using our API. Easy way to integrate our conversation into other applications.

You can send HTML inside API message. For example, as a content we can set:

Hi <b>user</b>, enjoy our product!

Themessage will be shown as follow:

Hi user, enjoy our product!
POST

/message/

Attributes
Type
Description
conversation
integer/string
ID of conversation. You can get all conversations details by this request
content
string
HTML can be used inside
user
integer
Unique agent ID, can be found here
source
integer
Find source types here
source_context
array
JSON array of additional fields if needed
curl -X POST -H "Authorization: Token <your_64_char_api_key>" -H "Content-Type: application/json" -d '{
    "conversation": 48553,
    "content": "Message sent using API",
    "user": 926,
    "source": 2,
    "source_context": {
      "name": "This is source_context used in API",
      "id": 123
    }
}' "https://app.userengage.com/api/public/message/"

Response

201 created
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://app.userengage.com/api/public/message/",
  "method": "POST",
  "headers": {
    "authorization": "Token <your_64_char_api_key>",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "{\n    \"conversation\": 748553,\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}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
var data = JSON.stringify({
  "conversation": 748553,
  "content": "Message sent using API",
  "user": 926,
  "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://app.userengage.com/api/public/message/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("content-type", "application/json");

xhr.send(data);
var request = require("request");

var options = { method: 'POST',
  url: 'https://app.userengage.com/api/public/message/',
  headers:
   { 'content-type': 'application/json',
     authorization: 'Token <your_64_char_api_key>' },
  body:
   { conversation: 748553,
     content: 'Message sent using API',
     user: 926,
     source: 2,
     source_context: { name: 'This is source_context used in API', id: 123 } },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
<?php

$request = new HttpRequest();
$request->setUrl('https://app.userengage.com/api/public/message/');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'content-type' => 'application/json',
  'authorization' => 'Token <your_64_char_api_key>'
));

$request->setBody('{
    "conversation": 748553,
    "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 requests

url = "https://app.userengage.com/api/public/message/"

payload = "{\n    \"conversation\": 748553,\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>",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
import http.client

conn = http.client.HTTPSConnection("app.userengage.com")

payload = "{\n    \"conversation\": 748553,\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>",
    'content-type': "application/json"
    }

conn.request("POST", "/api/public/message/", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))