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, options?: TwistApiOptions): TwistApi;

Creates a new Twist API client.

Parameters

ParameterTypeDescription
authTokenstringYour Twist API token.
options?TwistApiOptionsOptional 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

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)