Attaching PDF attachments fail in the API POST call

Hello,

This is for both creating a attachment on an existing card as well as with creating a new card.
However, if the attachment is a TXT file, the attachment is created so the call is being made properly. I’m guessing that a PDF has to be encoded but there is nothing in the docs that says that.

What would be the correct way to attach a PDF via the API?

I’m making the call in PowerShell, but I can also use cURL.

Thank you in advance.

Two things I’d recommend checking out.

First, this Glitch.com project that has a lot of examples on how to attach stuff via the API: https://glitch.com/~trello-attachments-api.

Second, I’d recommend following whatever the Trello web client does. To do so, open your browser’s console and watch the network as you attach a .pdf to a card.

Hi,
Thank you for the tip. However the glitch project and the web GUI is only for adding attachments to an existing card. I would like to create a new card with an attachment via the API which is where I am struggling with because of limited documentation:

The docs only say:
fileSource

string

Format: binary

https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-post

Update:
I figured it out. The file needs to be in a form using system.io.fileinfo . I’m on PowerShell 7 and I believe you might have to get into some .NET to make it work on PS5.1.


$FORM = @{
    idList     = "xxxxxx"
    pos        = "top"
    name       = "TestTest"
    fileSource = [system.io.fileinfo]"C:\Path\Path\File.pdf"
}

Invoke-RestMethod -Method Post -Uri "https://api.trello.com/1/cards?$APIKEY" -Form $FORM