Import Messages
curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/data_import/messages \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--data '{}'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/data_import/messages"
payload = {}
headers = {
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {apikey: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/data_import/messages', 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/data_import/messages",
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([
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>"
],
]);
$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/data_import/messages"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
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/data_import/messages")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/data_import/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_body{
"data": {
"3117": {
"success": true,
"data": {
"id": "1029",
"muid": "3117",
"conversationId": "r123_user_s12",
"sender": "s12",
"receiverType": "user",
"receiver": "r123",
"category": "message",
"type": "text",
"data": {
"text": "Hi there,",
"attachments": [
{
"name": "hi.png",
"extension": "png",
"size": "350.2",
"mimeType": "image/png",
"url": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png"
}
],
"metad2ata": {
"key": "value"
},
"custodata": {
"key": "value"
},
"entities": {
"sender": {
"entity": {
"uid": "s12",
"name": "user1",
"avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
"metadata": {
"key": "value"
},
"status": "offline",
"role": "default",
"createdAt": 1674228536,
"updatedAt": 1674232131
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "r123",
"name": "superhero",
"avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
"metadata": {
"key": "value"
},
"status": "offline",
"role": "default",
"createdAt": 1674228536,
"updatedAt": 1674232131,
"conversationId": "r123_user_s12"
},
"entityType": "user"
}
}
},
"sentAt": 1674104348,
"deliveredAt": 1674224684,
"readAt": 1674224684,
"updatedAt": 1674104348,
"tags": [
"tag1"
]
}
}
}
}Messages
Import Messages
The CometChat message import API allows customers to import their messages’ data into the CometChat systems.
POST
/
data_import
/
messages
Import Messages
curl --request POST \
--url https://{appId}.api-{region}.cometchat.io/v3/data_import/messages \
--header 'Content-Type: application/json' \
--header 'apikey: <api-key>' \
--data '{}'import requests
url = "https://{appId}.api-{region}.cometchat.io/v3/data_import/messages"
payload = {}
headers = {
"apikey": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {apikey: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://{appId}.api-{region}.cometchat.io/v3/data_import/messages', 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/data_import/messages",
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([
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"apikey: <api-key>"
],
]);
$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/data_import/messages"
payload := strings.NewReader("{}")
req, _ := http.NewRequest("POST", url, payload)
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/data_import/messages")
.header("apikey", "<api-key>")
.header("Content-Type", "application/json")
.body("{}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{appId}.api-{region}.cometchat.io/v3/data_import/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["apikey"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{}"
response = http.request(request)
puts response.read_body{
"data": {
"3117": {
"success": true,
"data": {
"id": "1029",
"muid": "3117",
"conversationId": "r123_user_s12",
"sender": "s12",
"receiverType": "user",
"receiver": "r123",
"category": "message",
"type": "text",
"data": {
"text": "Hi there,",
"attachments": [
{
"name": "hi.png",
"extension": "png",
"size": "350.2",
"mimeType": "image/png",
"url": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png"
}
],
"metad2ata": {
"key": "value"
},
"custodata": {
"key": "value"
},
"entities": {
"sender": {
"entity": {
"uid": "s12",
"name": "user1",
"avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
"metadata": {
"key": "value"
},
"status": "offline",
"role": "default",
"createdAt": 1674228536,
"updatedAt": 1674232131
},
"entityType": "user"
},
"receiver": {
"entity": {
"uid": "r123",
"name": "superhero",
"avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
"metadata": {
"key": "value"
},
"status": "offline",
"role": "default",
"createdAt": 1674228536,
"updatedAt": 1674232131,
"conversationId": "r123_user_s12"
},
"entityType": "user"
}
}
},
"sentAt": 1674104348,
"deliveredAt": 1674224684,
"readAt": 1674224684,
"updatedAt": 1674104348,
"tags": [
"tag1"
]
}
}
}
}For the complete error reference, see Error Guide.
Authorizations
API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).
Body
application/json
Wrapper for the messages.
Show child attributes
Show child attributes
Example:
{
"3118": {
"muid": "3118",
"sender": "s12",
"receiverType": "user",
"receiver": "r123",
"type": "text",
"category": "message",
"data": {
"text": "Hi there",
"attachments": [
{
"name": "hi.png",
"extension": "png",
"size": "350.2",
"mimeType": "image/png",
"url": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png"
}
],
"metadata": { "key": "value" },
"custodata": { "key": "value" }
},
"sentAt": "1674104348",
"deliveredAt": "1674224684",
"readAt": "1674224684",
"senderUserDetails": {
"uid": "s12",
"name": "user1",
"avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
"createdAt": "1674228536",
"metadata": { "key": "value" }
},
"receiverUserDetails": {
"uid": "r123",
"name": "superhero",
"type": "public",
"description": "Hello group",
"icon": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
"owner": "superhero1",
"avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
"createdAt": "1674228536",
"metadata": { "key": "value" }
},
"tags": ["tag1"],
"mentionedUserDetails": {
"example-uid-new": {
"uid": "example-uid-new",
"name": "example-uid"
}
}
}
}
Response
200 - application/json
Import Message(s)
Show child attributes
Show child attributes
Was this page helpful?
⌘I