feat(16-02): add AutotaskClient.getAttachmentContent()

- Fetches Tickets/{id}/Attachments/{attachmentId}, reads response.items?.[0]
- Confirmed live: per-attachment-ID GET is list-shaped, not {item:...}
This commit is contained in:
lorentz 2026-07-15 10:22:03 -04:00
parent 8be10db6e0
commit 9b65de72dc

View file

@ -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<Attachment | null> {
const url = `${this.config.apiUrl}/${entityName}/${entityId}/Attachments/${attachmentId}`;
const response = await this.makeApiCall<ApiResponse<Attachment>>(url, {
method: 'GET',
headers: this.getAuthHeaders(),
});
return response.items?.[0] ?? null;
}
// Time Entries specific methods
async getTimeEntriesByResource(resourceId: number): Promise<AutotaskTimeEntry[]> {
return this.queryEntity<AutotaskTimeEntry>('TimeEntries', {