Skip to main content
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://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
            }
          ],
          "metad2ata": {
            "key": "value"
          },
          "custodata": {
            "key": "value"
          },
          "entities": {
            "sender": {
              "entity": {
                "uid": "s12",
                "name": "user1",
                "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp",
                "metadata": {
                  "key": "value"
                },
                "status": "offline",
                "role": "default",
                "createdAt": 1674228536,
                "updatedAt": 1674232131
              },
              "entityType": "user"
            },
            "receiver": {
              "entity": {
                "uid": "r123",
                "name": "cometchat-uid-",
                "avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp",
                "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

apikey
string
header
required

API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).

Body

application/json
messages
object

Wrapper for the messages.

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://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp"
}
],
"metadata": { "key": "value" },
"custodata": { "key": "value" }
},
"sentAt": "1674104348",
"deliveredAt": "1674224684",
"readAt": "1674224684",
"senderUserDetails": {
"uid": "s12",
"name": "user1",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp",
"createdAt": "1674228536",
"metadata": { "key": "value" }
},
"receiverUserDetails": {
"uid": "r123",
"name": "cometchat-uid-",
"type": "public",
"description": "Hello group",
"icon": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp",
"owner": "cometchat-uid-1",
"avatar": "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-1.webp",
"createdAt": "1674228536",
"metadata": { "key": "value" }
},
"tags": ["tag1"]
}
}

Response

200 - application/json

Import Message(s)

data
object