A single conversation

GET returns a single Conversation or an HTTP 404 status if no conversation exists for the given conversation ID.

PUT creates or updates a conversation.

Path: /v1/{appId}/conversations/{conversationId}
Methods:GET, PUT

Example url: /v1/q3k1pa9d/conversations/order_fc_491731

Setting conversation data

PUT can be used to create a conversation or to update (a subset of) its attributes:

PUT https://api.talkjs.com/v1/{appId}/conversations/{conversationId}

{
  "participants": Array<string>,
  "subject": string,
  "welcomeMessages": Array<string>,
  "custom": Map<string, string>,
  "photoUrl": string
}

Example payload:

{
  "participants": ["123456", "654321"],
  "subject": "Black leather boots",
  "welcomeMessages": ["Hello there!", "I'm currently out of town, leave a message and I'll respond ASAP. :)"],
  "custom": {
    "productId": "454545"
  },
  "photoUrl": "https://example.com/productpictures/454545.png"
}

Note: PUT merges data with existing data, if any. For example, you cannot remove participants from a conversation by PUTing a list of participants that excludes some existing participants. If you want to remove participants from a conersation, use the Participation endpoint.

Getting created conversations

After you successfully create or update a conversation, you can fetch it back with a GET REST call.

GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}

The interface for this resource is the following:

type UnixMilliseconds = number;

type Conversation = {
  id: ConversationId;
  subject?: string;
  topicId?: string;
  photoUrl?: string;
  welcomeMessages?: string[];
  custom?: {[name: string]: string };
  participants: {
    [id: UserId]: {access: "ReadWrite" | "Read", notify: boolean}
  };
  createdAt: UnixMilliseconds;
}

Listing all conversations in the application

You can list all conversations ever created in your TalkJS application. The structure of the response is explained here.

GET https://api.talkjs.com/v1/{appId}/conversations

Filtering conversations

  • Filter by the last message's timestamp

It is possible to filter conversations by when the last message was sent to the conversation using the lastMessageBefore and lastMessageAfter filters.

lastMessageBefore and lastMessageAfter should be Unix timestamps expressed in milliseconds.

  • Filter by custom fields.

TalkJS also supports filtering by custom fields. The filter interface is precisely the same as the JavaScript SDK's Conversation Filter. In order to filter conversations by a custom field you need to URLencoded the JSON formatted filter.

You can use your favorite programming language to generate the conversation filter in the required JSON structure.

NodeJS example:

const filter = {custom: {category: ["==", "shoes"]}};
const encodedFilter = encodeURIComponent(JSON.stringify(filter));
const res = await fetch(`https://api.talkjs.com/v1/${appId}/conversations?filter=${encodedFilter}`);
const conversations = await res.json();

Filters can be combined together with limits and cursors.

Examples

GET https://api.talkjs.com/v1/{appId}/conversations
GET https://api.talkjs.com/v1/{appId}/conversations?lastMessageBefore=1521522849308&lastMessageAfter=1421522849732
GET https://api.talkjs.com/v1/{appId}/conversations?limit=50&lastMessageAfter=1421522849732
GET https://api.talkjs.com/v1/{appId}/conversations?startingAfter=c_21

// URL encoded version of the filter {"custom":{"category":["==","shoes"]}
GET https://api.talkjs.com/v1/{appId}/conversations?filter=%7B%22custom%22%3A%7B%22category%22%3A%5B%22%3D%3D%22%2C%22shoes%22%5D%7D

Limits and pagination

Similarly to other list requests, pagination and limits are applicable to listing conversations.

Deprecated: Conversations without a unique identifier

Path: /v1/{appId}/conversations/participants={userIds}
/v1/{appId}/conversations/participants={userIds};topic={topicId}
Methods:GET, PUT

Note: Do not use this endpoint in new projects. Instead, choose an appropriate conversation ID for your situation.

If your JavaScript code uses the getOrStartConversation method to start converstions then you need to use this endpoint. getOrStartConversation generates an internal conversation ID and this endpoint allows you to find (or create) a conversation without specifying this ID.

For this endpoint, conversations are uniquely identified by the following set of parameters: participants and an optional topic, which must match the parameters that were sent to getOrStartConversation {userIds} is a comma-separated list of user IDs. Include a {topicId} if you uniquely identify conversations per topic, omit it otherwise.

Example url: /v1/q3k1pa9d/conversations/participants=42,98;topic=612

Note that this endpoint only works if you create conversations using getOrStartConversation, which we do not recommend. It is not a general way to look up conversations that have two particular participants.