Attach Document To Case
pega.attach_document_to_caseAttach files or URLs to an existing case by providing the case ID and document data, supporting direct payload or base64 upload methods.
Instructions
Use this tool to attach files or URLs to an existing case. Required input: caseId. Attachment input mode 1: attachments array payload. Attachment input mode 2: fileName + fileContentBase64 (optional mimeType) for upload-then-attach flow. Returns: { ok: true, data: } on success. Standard failure format: { ok: false, error: { code, message, suggestion? } }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| caseId | Yes | Unique case identifier/handle. | |
| attachments | No | Optional direct attachment payload array sent to the case attachments endpoint. | |
| fileName | No | File name including extension. | |
| mimeType | No | Optional MIME type for base64 upload mode. | |
| fileContentBase64 | No | Optional document bytes encoded as base64. Used for upload-then-attach mode. | |
| originChannel | No | Optional channel hint, for example Web or Mobile. |
Implementation Reference
- src/tools/attachDocumentToCase.ts:31-35 (handler)The tool definition's execution handler for 'pega.attach_document_to_case'. It calls the underlying client method.
execute: async ({ pegaClient }, input) => { return withCaseAccessGuard(pegaClient, input, async () => { return pegaClient.attachDocumentToCase(input); }); } - src/client/pegaClient.ts:137-182 (handler)The core logic in PegaClient that implements document attachment, including potential temporary file upload if base64 content is provided.
async attachDocumentToCase(input: { caseId: string; attachments?: Array<Record<string, unknown>>; fileName?: string; mimeType?: string; fileContentBase64?: string; originChannel?: string; }): Promise<DocumentAttachResult> { const originChannel = input.originChannel ?? "Web"; let attachments = input.attachments; if ((!attachments || attachments.length === 0) && input.fileName && input.fileContentBase64) { const uploadedAttachmentId = await this.uploadTemporaryAttachmentFromBase64({ fileName: input.fileName, mimeType: input.mimeType ?? "application/octet-stream", fileContentBase64: input.fileContentBase64, originChannel }); attachments = [{ type: "File", category: "File", ID: uploadedAttachmentId }]; } if (!attachments || attachments.length === 0) { throw new Error("Attachment payload is missing. Provide attachments[] or base64 file fields."); } const result = await this.request<unknown>( `${this.getCasesApiBasePath()}/cases/${encodeURIComponent(input.caseId)}/attachments`, { method: "POST", headers: { "x-origin-channel": originChannel }, body: JSON.stringify({ attachments }) } ); return { success: true, caseId: input.caseId, documentName: input.fileName, message: "Attachment request completed", details: result }; } - src/tools/attachDocumentToCase.ts:5-36 (registration)Definition and registration of the 'pega.attach_document_to_case' tool.
export const attachDocumentToCaseToolDefinition = defineTool({ name: "pega.attach_document_to_case", title: "Attach Document To Case", description: [ "Use this tool to attach files or URLs to an existing case.", "Required input: caseId.", "Attachment input mode 1: attachments array payload.", "Attachment input mode 2: fileName + fileContentBase64 (optional mimeType) for upload-then-attach flow.", "Returns: { ok: true, data: <attachment result> } on success." ].join(" "), inputSchema: attachDocumentToCaseSchema, invalidInputMessage: "caseId is required, plus attachments[] or fileName+fileContentBase64", validateInput: (input) => { const hasAttachments = Array.isArray(input.attachments) && input.attachments.length > 0; const hasUploadFields = Boolean(input.fileName && input.fileContentBase64); if (!hasAttachments && !hasUploadFields) { return { code: "INVALID_INPUT", message: "attachments[] or fileName+fileContentBase64 is required", suggestion: "Provide either an attachments array or base64 upload fields." }; } return null; }, execute: async ({ pegaClient }, input) => { return withCaseAccessGuard(pegaClient, input, async () => { return pegaClient.attachDocumentToCase(input); }); } });