Skip to content

Server API examples

Use these endpoints from your backend with your API key in x-api-key.

New here? Start with the Quick start. For full server configuration, see Server setup.


Headers

Include these headers on every request:

  • x-api-key: {API_KEY}
  • Content-Type: application/json

Create a room — POST {API_URL}/chat/rooms

bash
curl -s -X POST "${SENDSAR_API_URL}/chat/rooms" \
  -H "x-api-key: ${SENDSAR_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Support",
    "participants": [
      { "id": "user_abc123", "username": "Alice" },
      { "id": "agent_001", "username": "Support" }
    ]
  }'
js
await fetch(`${process.env.SENDSAR_API_URL}/chat/rooms`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.SENDSAR_API_KEY,
  },
  body: JSON.stringify({
    name: "Support",
    participants: [
      { id: "user_abc123", username: "Alice" },
      { id: "agent_001", username: "Support" },
    ],
  }),
});
php
Http::withHeaders(['x-api-key' => config('sendsar.api_key')])
    ->post(config('sendsar.api_url').'/chat/rooms', [
        'name' => 'Support',
        'participants' => [
            ['id' => 'user_abc123', 'username' => 'Alice'],
            ['id' => 'agent_001', 'username' => 'Support'],
        ],
    ]);
py
await client.post(
    f"{API_URL}/chat/rooms",
    headers={"x-api-key": API_KEY, "Content-Type": "application/json"},
    json={
        "name": "Support",
        "participants": [
            {"id": "user_abc123", "username": "Alice"},
            {"id": "agent_001", "username": "Support"},
        ],
    },
)
go
body, _ := json.Marshal(map[string]any{
    "name": "Support",
    "participants": []map[string]string{
        {"id": "user_abc123", "username": "Alice"},
        {"id": "agent_001", "username": "Support"},
    },
})
req, _ := http.NewRequest(http.MethodPost, apiURL+"/chat/rooms", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", apiKey)
http.DefaultClient.Do(req)
ruby
Faraday.post("#{api_url}/chat/rooms", {
  name: "Support",
  participants: [
    { id: "user_abc123", username: "Alice" },
    { id: "agent_001", username: "Support" },
  ],
}.to_json, { "x-api-key" => api_key, "Content-Type" => "application/json" })

Use the room id (UUID) from the response when opening a conversation in your app.


Register a device token

Clients (session JWT): POST {API_URL}/users/me/device-tokens — or client.registerDeviceToken() after connect().

Server (API key): POST {API_URL}/users/{userId}/device-tokens.

Full guide: Push & device tokens.

Sendsar — headless chat for B2B platforms