Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Upload attachment with API on VBA

Damien Lohier February 29, 2024

Hello,
I try to upload a file to a Trello card with my VBA application, but I always receive status 400 from the API.

 

Here is what I see in network tab of Firefox when I upload a file:

 

-----------------------------21770600522523212291266470825
Content-Disposition: form-data; name="dsc"

c27e21f98df1b3ed8f[...]7d49d9daf562557675dc7
-----------------------------21770600522523212291266470825
Content-Disposition: form-data; name="numOfFiles"

1
-----------------------------21770600522523212291266470825
Content-Disposition: form-data; name="fileIdx"

0
-----------------------------21770600522523212291266470825
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

this is a test file


-----------------------------21770600522523212291266470825-

I tried to send a POST request with a body having the same format, but I got a status 400 (Bad request).
I have just removed the "dsc" part, I don't know what is it or how I can calculate it. Is it mandatory ?


Query: https://api.trello.com/1/cards/[my card id]/attachments

Am I doing something wrong ?

Again, the API docs are not very useful in this case:

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

2 answers

1 accepted

0 votes
Answer accepted
Damien Lohier July 9, 2024

Hello,

I finally managed to upload attachment to Trello with VBA application !

Here is my function:

Public Sub AddAttachmentToCard(Id As String, ParamArray attachments() As Variant)
    If UBound(attachments) > -1 Then
        Dim i As Integer
        For i = LBound(attachments) To UBound(attachments)
             If attachments(i) <> "" Then
                 Dim shellStr As String
                 shellStr = "curl.exe --form file=""@" & attachments(i) & """ --form key=" & APIKey & " --form token=" & APIToken & " https://api.trello.com/1/cards/" & Id & "/attachments"
                 Shell shellStr, vbHide
             End If
        Next
    End If
End Sub

 Call it with: AddAttachmentToCard trello_id, attachmentPath1, attachmentPath2, ...

0 votes
Sal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 1, 2024

Hi @Damien Lohier! For this type of question, I recommend you post at the Atlassian Developer Community at https://community.developer.atlassian.com/c/trello/42. This is the best place for you to get answers about issues with custom scripts you've developed using Trello's API. Also, other developers (including Trello engineers) are actively interacting there, and they might be better suited to help you with that. Thanks for your understanding! 

Damien Lohier March 5, 2024

Hello, I have posted on the Developer community and waiting for an answer, thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events