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": "cometchat-uid-3_user_cometchat-uid-5",
"sender": "cometchat-uid-3",
"receiverType": "user",
"receiver": "cometchat-uid-5",
"category": "message",
"type": "text",
"data": {
"text": "test hello",
"metadata": {
"key1": "val1"
},
"entities": {
"sender": {
"entity": {
"uid": "cometchat-uid-3",
"name": "Nancy Grace",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "cometchat-uid-5",
"name": "John Paul",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-5.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550,
"conversationId": "cometchat-uid-3_user_cometchat-uid-5"
},
"entityType": "user"
}
}
},
"sentAt": 1638423490,
"updatedAt": 1638423490,
"parentId": "1"
}
}Send Threaded Message
Send a threaded CometChat message by parent message ID with REST API to reply inside an existing thread.
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": "cometchat-uid-3_user_cometchat-uid-5",
"sender": "cometchat-uid-3",
"receiverType": "user",
"receiver": "cometchat-uid-5",
"category": "message",
"type": "text",
"data": {
"text": "test hello",
"metadata": {
"key1": "val1"
},
"entities": {
"sender": {
"entity": {
"uid": "cometchat-uid-3",
"name": "Nancy Grace",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-3.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "cometchat-uid-5",
"name": "John Paul",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-5.webp",
"status": "offline",
"role": "default",
"createdAt": 1638361550,
"conversationId": "cometchat-uid-3_user_cometchat-uid-5"
},
"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
The receiver of the message.
The receiverType of the message. either user or group
user, group Category of the message. The available categories are message and custom.
message, custom Type of the message. The available values are text, image, file, audio, video.
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
Create Message
Response data
Show child attributes
Show child attributes
Was this page helpful?