diff --git a/lib/services/autotask-client.ts b/lib/services/autotask-client.ts index 127cda5..bb8492f 100644 --- a/lib/services/autotask-client.ts +++ b/lib/services/autotask-client.ts @@ -435,6 +435,26 @@ export class AutotaskClient { return response.items || []; } + // Fetches a single attachment's full content (base64 `data` populated). + // Confirmed live: the per-attachment-ID GET returns `{items:[...]}` + // (list-shaped), NOT `{item:...}` like getEntityById/uploadAttachment — + // do not "fix" this to read response.item, that would silently return + // undefined content. + async getAttachmentContent( + entityName: string, + entityId: number, + attachmentId: number + ): Promise { + const url = `${this.config.apiUrl}/${entityName}/${entityId}/Attachments/${attachmentId}`; + + const response = await this.makeApiCall>(url, { + method: 'GET', + headers: this.getAuthHeaders(), + }); + + return response.items?.[0] ?? null; + } + // Time Entries specific methods async getTimeEntriesByResource(resourceId: number): Promise { return this.queryEntity('TimeEntries', {