Skip to main content

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

ParameterTypeDescription
authTokenstringYour Twist API token.
baseUrl?stringOptional custom API base URL. If not provided, defaults to Twist's standard API endpoint.

Returns

TwistApi

Properties

PropertyModifierType
channelspublicChannelsClient
commentspublicCommentsClient
conversationMessagespublicConversationMessagesClient
conversationspublicConversationsClient
groupspublicGroupsClient
inboxpublicInboxClient
reactionspublicReactionsClient
searchpublicSearchClient
threadspublicThreadsClient
userspublicUsersClient
workspacespublicWorkspacesClient
workspaceUserspublicWorkspaceUsersClient

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

ParameterTypeDescription
...requestsTBatch 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)