trello_create_card_attachment
Attach a URL or upload a local file to a Trello card by providing the card ID and attachment source.
Instructions
Attach a URL or local file to a Trello card. Provide either a url (for link attachments) or filePath (for file uploads from the local filesystem).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | No | Trello API key (optional if TRELLO_API_KEY env var is set) | |
| token | No | Trello API token (optional if TRELLO_TOKEN env var is set) | |
| cardId | Yes | ID or URL of the card (e.g. "abc123" or "https://trello.com/c/abc123/1-title") | |
| url | No | URL to attach as a link (e.g. "https://example.com/doc.pdf"). Cannot be used with filePath. | |
| filePath | No | Absolute path to a local file to upload (e.g. "/home/user/report.pdf"). Cannot be used with url. | |
| name | No | Optional display name for the attachment | |
| mimeType | No | Optional MIME type (e.g. "application/pdf", "image/png"). Auto-detected for file uploads if omitted. | |
| setCover | No | If true, set this attachment as the card cover image |
Implementation Reference
- src/trello/client.ts:605-649 (helper)TrelloClient.createCardAttachment method that handles both file upload (multipart/form-data) and URL attachment (JSON POST) to /cards/{cardId}/attachments.
async createCardAttachment(cardId: string, data: { url?: string; filePath?: string; name?: string; mimeType?: string; setCover?: boolean; }): Promise<TrelloApiResponse<TrelloAttachment>> { if (data.filePath) { // File upload via multipart/form-data const fileBuffer = await readFile(data.filePath); const fileName = data.name || basename(data.filePath); const blob = new Blob([fileBuffer], { type: data.mimeType || 'application/octet-stream' }); const formData = new FormData(); formData.append('file', blob, fileName); if (data.name) formData.append('name', data.name); if (data.mimeType) formData.append('mimeType', data.mimeType); if (data.setCover !== undefined) formData.append('setCover', String(data.setCover)); return this.makeRequest<TrelloAttachment>( `/cards/${cardId}/attachments`, { method: 'POST', body: formData as any }, `Upload file attachment to card ${cardId}` ); } // URL attachment via JSON body const body: Record<string, any> = {}; if (data.url) body.url = data.url; if (data.name) body.name = data.name; if (data.mimeType) body.mimeType = data.mimeType; if (data.setCover !== undefined) body.setCover = data.setCover; return this.makeRequest<TrelloAttachment>( `/cards/${cardId}/attachments`, { method: 'POST', body: JSON.stringify(body) }, `Create URL attachment on card ${cardId}` ); }