Send Threaded Message
curl --request POST \
--url https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--header 'onBehalfOf: <onbehalfof>' \
--data '
{
"receiver": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "Hi Tom!",
"metadata": {
"key1": "value1",
"key2": "value2"
}
},
"multipleReceivers": {
"uids": [
"uid1",
"uid2"
],
"guids": [
"guid1"
]
},
"tags": [
"tag1"
]
}
'import requests
url = "https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread"
payload = {
"receiver": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "Hi Tom!",
"metadata": {
"key1": "value1",
"key2": "value2"
}
},
"multipleReceivers": {
"uids": ["uid1", "uid2"],
"guids": ["guid1"]
},
"tags": ["tag1"]
}
headers = {
"onBehalfOf": "<onbehalfof>",
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
onBehalfOf: '<onbehalfof>',
apikey: '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
receiver: '<string>',
category: 'message',
type: 'text',
data: {text: 'Hi Tom!', metadata: {key1: 'value1', key2: 'value2'}},
multipleReceivers: {uids: ['uid1', 'uid2'], guids: ['guid1']},
tags: ['tag1']
})
};
fetch('https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'receiver' => '<string>',
'category' => 'message',
'type' => 'text',
'data' => [
'text' => 'Hi Tom!',
'metadata' => [
'key1' => 'value1',
'key2' => 'value2'
]
],
'multipleReceivers' => [
'uids' => [
'uid1',
'uid2'
],
'guids' => [
'guid1'
]
],
'tags' => [
'tag1'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>",
"onBehalfOf: <onbehalfof>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread"
payload := strings.NewReader("{\n \"receiver\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"Hi Tom!\",\n \"metadata\": {\n \"key1\": \"value1\",\n \"key2\": \"value2\"\n }\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"uid1\",\n \"uid2\"\n ],\n \"guids\": [\n \"guid1\"\n ]\n },\n \"tags\": [\n \"tag1\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("onBehalfOf", "<onbehalfof>")
req.Header.Add("apikey", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread")
.header("onBehalfOf", "<onbehalfof>")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"receiver\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"Hi Tom!\",\n \"metadata\": {\n \"key1\": \"value1\",\n \"key2\": \"value2\"\n }\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"uid1\",\n \"uid2\"\n ],\n \"guids\": [\n \"guid1\"\n ]\n },\n \"tags\": [\n \"tag1\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["onBehalfOf"] = '<onbehalfof>'
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"receiver\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"Hi Tom!\",\n \"metadata\": {\n \"key1\": \"value1\",\n \"key2\": \"value2\"\n }\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"uid1\",\n \"uid2\"\n ],\n \"guids\": [\n \"guid1\"\n ]\n },\n \"tags\": [\n \"tag1\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "2",
"conversationId": "superhero3_user_superhero5",
"sender": "superhero3",
"receiverType": "user",
"receiver": "superhero5",
"category": "message",
"type": "text",
"data": {
"text": "test hello",
"metadata": {
"key1": "val1"
},
"entities": {
"sender": {
"entity": {
"uid": "superhero3",
"name": "Spiderman",
"avatar": "https://data-us.cometchat.io/assets/images/avatars/spiderman.png",
"status": "offline",
"role": "default",
"createdAt": 1638361550
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "superhero5",
"name": "Cyclops",
"avatar": "https://data-us.cometchat.io/assets/images/avatars/cyclops.png",
"status": "offline",
"role": "default",
"createdAt": 1638361550,
"conversationId": "superhero3_user_superhero5"
},
"entityType": "user"
}
}
},
"sentAt": 1638423490,
"updatedAt": 1638423490,
"parentId": "1"
}
}Messages
Send Threaded Message
Sends Threaded Message on behalf of a user.
POST
/
messages
/
{id}
/
thread
Send Threaded Message
curl --request POST \
--url https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--header 'onBehalfOf: <onbehalfof>' \
--data '
{
"receiver": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "Hi Tom!",
"metadata": {
"key1": "value1",
"key2": "value2"
}
},
"multipleReceivers": {
"uids": [
"uid1",
"uid2"
],
"guids": [
"guid1"
]
},
"tags": [
"tag1"
]
}
'import requests
url = "https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread"
payload = {
"receiver": "<string>",
"category": "message",
"type": "text",
"data": {
"text": "Hi Tom!",
"metadata": {
"key1": "value1",
"key2": "value2"
}
},
"multipleReceivers": {
"uids": ["uid1", "uid2"],
"guids": ["guid1"]
},
"tags": ["tag1"]
}
headers = {
"onBehalfOf": "<onbehalfof>",
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
onBehalfOf: '<onbehalfof>',
apikey: '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
receiver: '<string>',
category: 'message',
type: 'text',
data: {text: 'Hi Tom!', metadata: {key1: 'value1', key2: 'value2'}},
multipleReceivers: {uids: ['uid1', 'uid2'], guids: ['guid1']},
tags: ['tag1']
})
};
fetch('https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'receiver' => '<string>',
'category' => 'message',
'type' => 'text',
'data' => [
'text' => 'Hi Tom!',
'metadata' => [
'key1' => 'value1',
'key2' => 'value2'
]
],
'multipleReceivers' => [
'uids' => [
'uid1',
'uid2'
],
'guids' => [
'guid1'
]
],
'tags' => [
'tag1'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>",
"onBehalfOf: <onbehalfof>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread"
payload := strings.NewReader("{\n \"receiver\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"Hi Tom!\",\n \"metadata\": {\n \"key1\": \"value1\",\n \"key2\": \"value2\"\n }\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"uid1\",\n \"uid2\"\n ],\n \"guids\": [\n \"guid1\"\n ]\n },\n \"tags\": [\n \"tag1\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("onBehalfOf", "<onbehalfof>")
req.Header.Add("apikey", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread")
.header("onBehalfOf", "<onbehalfof>")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"receiver\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"Hi Tom!\",\n \"metadata\": {\n \"key1\": \"value1\",\n \"key2\": \"value2\"\n }\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"uid1\",\n \"uid2\"\n ],\n \"guids\": [\n \"guid1\"\n ]\n },\n \"tags\": [\n \"tag1\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appid}.api-{region}.cometchat.io/v3/messages/{id}/thread")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["onBehalfOf"] = '<onbehalfof>'
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"receiver\": \"<string>\",\n \"category\": \"message\",\n \"type\": \"text\",\n \"data\": {\n \"text\": \"Hi Tom!\",\n \"metadata\": {\n \"key1\": \"value1\",\n \"key2\": \"value2\"\n }\n },\n \"multipleReceivers\": {\n \"uids\": [\n \"uid1\",\n \"uid2\"\n ],\n \"guids\": [\n \"guid1\"\n ]\n },\n \"tags\": [\n \"tag1\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "2",
"conversationId": "superhero3_user_superhero5",
"sender": "superhero3",
"receiverType": "user",
"receiver": "superhero5",
"category": "message",
"type": "text",
"data": {
"text": "test hello",
"metadata": {
"key1": "val1"
},
"entities": {
"sender": {
"entity": {
"uid": "superhero3",
"name": "Spiderman",
"avatar": "https://data-us.cometchat.io/assets/images/avatars/spiderman.png",
"status": "offline",
"role": "default",
"createdAt": 1638361550
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "superhero5",
"name": "Cyclops",
"avatar": "https://data-us.cometchat.io/assets/images/avatars/cyclops.png",
"status": "offline",
"role": "default",
"createdAt": 1638361550,
"conversationId": "superhero3_user_superhero5"
},
"entityType": "user"
}
}
},
"sentAt": 1638423490,
"updatedAt": 1638423490,
"parentId": "1"
}
}Authorizations
API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).
Headers
UID of the user on whose behalf the action is performed.
Path Parameters
Id of the message for which thread message to be sent
Body
application/json
The receiver of the message.
The receiverType of the message. either user or group
Available options:
user, group Category of the message. The available categories are message and custom.
Available options:
message, custom Type of the message. The available values are text, image, file, audio, video.
Available options:
text, image, file, audio, video JSON containing message attributes.
JSON containing array of UIDs and GUID for whom the message must be sent. Format for multiple receivers - {"uids": ["uid1","uid2"], "guids":["guid1"]}
A list of tags to identify specific messages.
Response
200 - application/json
Create Message
Response data
Show child attributes
Show child attributes
⌘I