Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a card with an attachment?

Nir Modiano
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 18, 2020

When trying to create a card using the API through the developers website with an attachment (see below)

var request = require("request");

var options = {
  method: 'POST',
  url: 'https://api.trello.com/1/cards',
  qs: {
    name: 'New Card',
    desc: 'this is the description',
    idList: '{my idList here}',
    fileSource: 'data:text/plain;name=ads.txt;base64,Z29vZ2xlLmNvbSwgcHViLTMyNDQzOTEzNDI4NDE4NjksIERJUkVDVCwgZjA4YzQ3ZmVjMDk0MmZhMA==',
    keepFromSource: 'all',
    key: '{my key here}',
    token: '{my token here}'
  }
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

 

I get this as the response:

{"message":"Must provide either url or file""error":"VALIDATOR_INVALID_VALUE"}

But I am providing a "fileSource" so I'm not sure why it's telling me that I must provide either url or file when I am providing a file.  I can't seem to get around this.

Any help would be appreciated.

Thanks,
Nir

 

1 answer

0 votes
Iain Dooley
Community Champion
March 19, 2020

@Nir Modiano I've never been able to make "real" file uploads work with the API, I just assume it doesn't work. Maybe @bentley has some clues (I'll be listening closely)!

Even looking at whether or not attachments are files or links via the API seems to always return links -- as far as I can tell, attachments are always links, but somehow if you upload them via the Trello interface it flags them differently so you see the "PDF" or "DOC" icon, but via the API, I've only been able to create a link.

If I don't want this to look like it's a link, and instead want it to look like a file, I actually download it to Drive first then post the drive link to the file.

bentley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 19, 2020

I think that I've only ever gotten a file to upload via API if I sent it as form-data.

I put together this Glitch project to play around with attachments awhile go. Taking a look at it might be helpful: https://glitch.com/~trello-attachments-api

I'd also recommend asking questions about the API over here: https://community.developer.atlassian.com/c/trello. There are other developers familiar with Trello that might be able to offer better advice.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events