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, options?: TwistApiOptions): TwistApi;
Creates a new Twist API client.
Parameters
| Parameter | Type | Description |
|---|---|---|
authToken | string | Your Twist API token. |
options? | TwistApiOptions | Optional configuration options. |
Returns
TwistApi
Example
// Basic usage
const api = new TwistApi('your-api-token')
// With custom base URL
const api = new TwistApi('your-api-token', { baseUrl: 'https://custom.api.com' })
// With custom fetch (e.g., for Obsidian)
const api = new TwistApi('your-api-token', { customFetch: myCustomFetch })
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)