TwistApi
The main API client for interacting with the Twist REST API.
Example
import { TwistApi } from '@doist/twist-sdk'
const api = new TwistApi('your-api-token')
const user = await api.users.getSessionUser()
Constructors
Constructor
new TwistApi(authToken: string, baseUrl?: string): TwistApi;
Creates a new Twist API client.
Parameters
Parameter | Type | Description |
---|---|---|
authToken | string | Your Twist API token. |
baseUrl? | string | Optional custom API base URL. If not provided, defaults to Twist's standard API endpoint. |
Returns
TwistApi
Properties
Property | Modifier | Type |
---|---|---|
channels | public | ChannelsClient |
comments | public | CommentsClient |
conversationMessages | public | ConversationMessagesClient |
conversations | public | ConversationsClient |
groups | public | GroupsClient |
inbox | public | InboxClient |
reactions | public | ReactionsClient |
search | public | SearchClient |
threads | public | ThreadsClient |
users | public | UsersClient |
workspaces | public | WorkspacesClient |
workspaceUsers | public | WorkspaceUsersClient |
Methods
batch()
batch<T>(...requests: T): Promise<BatchResponseArray<T>>;
Executes multiple API requests in a single HTTP call using the batch endpoint.
Type Parameters
Type Parameter |
---|
T extends readonly BatchRequestDescriptor <unknown >[] |
Parameters
Parameter | Type | Description |
---|---|---|
...requests | T | Batch request descriptors (obtained by passing { batch: true } to API methods) |
Returns
Promise
<BatchResponseArray
<T
>>
Array of batch responses with processed data
Example
const results = await api.batch(
api.workspaceUsers.getUserById(123, 456, { batch: true }),
api.workspaceUsers.getUserById(123, 789, { batch: true })
)
console.log(results[0].data.name, results[1].data.name)