Batch
You can use the batch endpoint to perform multiple operations with a single REST call. You can include a maximum of 10 operations in a single batch request.
For batch requests, the REST API rate limits support 500 burst requests, 100 maximum queue length, and 1 batch request per second.
Replace {appId}
in the baseUrl with your own App ID, which you can find under
Settings in your TalkJS dashboard.
The payload is an array of operations. Each operation has the format:
1[sequence_number, method, path, payload, options]
Name | Type | Description | Example |
---|---|---|---|
sequence_number | number | Unique identifier of the operation. Can be any number. | 1 |
method | string | Indicates the HTTP method for the operation. | GET |
path | string | Path of the REST API endpoint for the operation that's appended to the /v1/{appId} baseUrl. | /users/user_01 |
payload (optional) | object | JSON payload. You can use this for PUT and POST requests to specify the payload associated with the REST API operation. You can also use it with string keys and values to specify query parameters to filter results of a GET request. | { name: "Alice" } |
options (optional) | object | Mapping containing the key api_version , and a string value with the API version. | {"api_version": "2021-01-01"} |
1type Operation = [2 sequence_number: number,3 method: string,4 path: string,5 payload?: any,6 options?: {"api_version": string}7]89type Payload = Operation[];
1[2 [1, "GET", "/users/user_01"],3 [2, "GET", "/users/user_01/conversations", {"limit": "30", "unreadsOnly": "true", "lastMessageAfter": "17100697559480"}],4 [3, "POST", "/conversations/conv_01/messages", [{"text": "This is a system message", "type": "SystemMessage"}]],5 [4, "PUT", "/users/user_02", {"name": "Alice"}, {"api_version": "2021-01-01"}],6 [5, "GET", "/non/existing/endpoint"]7]
The operations may execute in a different order than the one specified in the request. If you have operations that need to happen in a certain order (for example, first creating a user and then setting them as a participant to a conversation), then you need to request those in separate calls.
The response will be an array of operation responses. Each operation response has the format:
1[sequence_number, http_status_code, operation_response]
Name | Type | Description | Example |
---|---|---|---|
sequence_number | number | Unique identifier of the operation. Corresponds to the sequence_number in the request. | 1 |
http_status_code | number | Numeric HTTP status code for the REST operation. | 200 |
operation_response | string | The JSON data returned by the REST operation. | [{"id": "msg_1821ZuPQL8tqKUWqXp8YDF"}] |
1type OperationResponse = [2 sequence_number: number,3 http_status_code: number,4 operation_response: any5]67type Response = OperationResponse[];
1[2 [1, 200, { "id": "user_01", "name": "Alice", ... }],3 [2, 200, { "data": [{"id": "conv_01", ...}, ...] }],4 [3, 200, [{"id": "msg_1821ZuPQL8tqKUWqXp8YDF"}]],5 [4, 200, {}],6 [5, 404, "Could not find route GET /non/existing/endpoint"]7]