Skip to main content

AttachmentsClient

Client for uploading file attachments to Twist.

Attachments are uploaded independently, then referenced by passing the returned Attachment into the attachments array of comments.createComment, conversationMessages.createMessage, and similar calls.

Extends​

  • BaseClient

Constructors​

Constructor​

new AttachmentsClient(config: ClientConfig): AttachmentsClient;

Parameters​

ParameterType
configClientConfig

Returns​

AttachmentsClient

Inherited from​

BaseClient.constructor

Properties​

PropertyModifierType
apiTokenreadonlystring
baseUrl?readonlystring
customFetch?readonlyCustomFetch
defaultVersionreadonly"v3" | "v4"

Methods​

getBaseUri()​

protected getBaseUri(version?: "v3" | "v4"): string;

Gets the base URI for API requests with proper trailing slash handling. This method fixes the trailing slash bug that occurred when using custom baseUrl.

Parameters​

ParameterTypeDescription
version?"v3" | "v4"Optional API version override. Defaults to the configured version or 'v3'

Returns​

string

Base URI with guaranteed trailing slash for proper URL resolution

Inherited from​

BaseClient.getBaseUri

getLinkBaseUrl()​

protected getLinkBaseUrl(): string | undefined;

Base URL for entity web links, or undefined to use getFullTwistURL's default web app.

Returns​

string | undefined

Inherited from​

BaseClient.getLinkBaseUrl

upload()​

upload(args: UploadAttachmentArgs): Promise<{
[key: string]: unknown;
attachmentId: string;
description?: string | null;
duration?: string | null;
fileName?: string | null;
fileSize?: number | null;
image?: string | null;
imageHeight?: number | null;
imageWidth?: number | null;
title?: string | null;
underlyingType?: string | null;
uploadState?: string | null;
url?: string | null;
urlType: string;
video?: string | null;
videoAutoPlay?: boolean | null;
videoType?: string | null;
}>;

Uploads a file and returns the created Attachment.

Mirrors the canonical multipart upload used by twist-web: POST /attachments/upload with the file binary plus file_name, file_size, attachment_id, and underlying_type form fields.

Parameters​

ParameterTypeDescription
argsUploadAttachmentArgsThe file to upload and optional metadata.

Returns​

Promise<{ [key: string]: unknown; attachmentId: string; description?: string | null; duration?: string | null; fileName?: string | null; fileSize?: number | null; image?: string | null; imageHeight?: number | null; imageWidth?: number | null; title?: string | null; underlyingType?: string | null; uploadState?: string | null; url?: string | null; urlType: string; video?: string | null; videoAutoPlay?: boolean | null; videoType?: string | null; }>

The created attachment, ready to attach to a comment or message.

Example​

import { readFile } from 'node:fs/promises'

const attachment = await api.attachments.upload({
file: await readFile('./diagram.png'),
fileName: 'diagram.png',
})

await api.comments.createComment({
threadId: 789,
content: 'See attached',
attachments: [attachment],
})