Newer Version Available

This content describes an older version of this product. View Latest

Getting Started with the Chat REST API

Learn how to start, confirm, and end a Chat session with the Chat REST API.

This guide explains how to use the Chat REST API. If you’re not already using Chat, check out Messaging for In-App and Web, a newer chat solution for websites and mobile apps.

Note

Retrieve Your Chat API Endpoint

Your Chat API endpoint is a unique URL that lets you access data from your organization’s Chat sessions. To find your organization’s Chat API endpoint:
  1. From Setup, in the Quick Find box, enter Chat Settings, and then select Chat Settings.
  2. Retrieve the hostname from the Chat API Endpoint. The hostname is the URL without “/chat/rest/” at the end, for example, “https://yourChatApiEndpoint.com”. Substitute hostname in the Chat API endpoints with this URL.
The hostname that you retrieve from the Chat Settings page in Settings.

Start a Chat Session

To start a Chat session, send a SessionId request. Replace hostname with the URL that you retrieved from Chat API Endpoint.

Use these Request Headers.
  • X-LIVEAGENT-AFFINITY
  • X-LIVEAGENT-API-VERSION

Confirm the Chat Session Started

A ChatRequestSuccess response tells you that the Chat session started.

Then wait for a ChatEstablished response. That response tells you that an agent accepted the chat session.

Now you’re ready to send, for example, Messages requests. Before you send further requests, wait until you receive the ChatRequestSuccess and ChatEstablished responses, otherwise the API throws a Null Pointer exception, and you receive a 500 error.

End the Chat Session

The Chat session ends when you send a ChatEnd request or send a DELETE SessionId request. In both request types, X-LIVEAGENT-SESSION-KEY is the unique ID of the Chat session that you want to end.

Here’s the ChatEnd request.

Use these Request Headers.
  • X-LIVEAGENT-AFFINITY
  • X-LIVEAGENT-API-VERSION
  • X-LIVEAGENT-SESSION-KEY
  • X-LIVEAGENT-SEQUENCE

Here’s the SessionId request.

Use these Request Headers.
  • X-LIVEAGENT-AFFINITY
  • X-LIVEAGENT-API-VERSION