Skip to main content

AttachmentsClient

Client for uploading attachments and reading thread images.

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"v1"

Methods​

getBaseUri()​

protected getBaseUri(): string;

Returns the base URI for an API request, with a guaranteed trailing slash so relative paths resolve cleanly through URL.

Returns​

string

Inherited from​

BaseClient.getBaseUri

getLinkBaseUrl()​

protected getLinkBaseUrl(): string | undefined;

Base URL for entity web links, or undefined to use getFullCommsURL's default web app. Trailing-slash normalization happens in getFullCommsURL, so the configured value is returned verbatim.

Returns​

string | undefined

Inherited from​

BaseClient.getLinkBaseUrl

readImage()​

readImage(uploadId: string, threadId: string): Promise<{
byteLength: number;
dataBase64: string;
mimeType: "image/png" | "image/jpeg" | "image/webp";
}>;

Read one thread image under the caller's content scope.

Parameters​

ParameterType
uploadIdstring
threadIdstring

Returns​

Promise<{ byteLength: number; dataBase64: string; mimeType: "image/png" | "image/jpeg" | "image/webp"; }>


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: 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: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
content: 'See attached',
attachments: [attachment],
})