-1

How do you add multiple labels to a single card with a single HTTPRequest using the Trello API? I have the following code:

StringBuilder uri = new StringBuilder();
uri.append(TRELLO_URL + "/cards/").append(this.id).append("/idLabels?value=").append(labelIds[0]);
for(int i = 1; i < labelIds.length; i++) {
    uri.append("&value=").append(labelIds[i]);
}
uri.append("&key=").append(key).append("&token=").append(token);

The Trello API states to separate multiple labels by using a comma (%2C) however both produce a 400. Does anyone have any experience with this?

I tried numerous solutions, such as replacing &value= with %2C however to no avail. There's little documentation on this solution and the Trello API is notorious with forcing you to always include everything in the URI when this could easily be solved if they accepted bodies.

  • If you really meant `2%C` then that's your problem... it's `%2C` – Jim Garrison Nov 10 '22 at 20:07
  • I would recommend getting a 'simple' curl or wget request working first before trying to make your requests programmatically. Then you could add that example to your question. – hooknc Nov 10 '22 at 20:39

1 Answers1

1

Currently you are trying to use endpoint "Add a label to a card" (https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-post) which is designed to add a single Label to a Card.

To add multiple labels you need to use endpoint "Update a card" (https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put).

Based on your code it would look more or less like this:

StringBuilder uri = new StringBuilder();
uri.append(TRELLO_URL + "/cards/").append(this.id).append("?idLabels=").append(labelIds[0]);
for(int i = 1; i < labelIds.length; i++) {
    uri.append(",").append(labelIds[i]);
}
uri.append("&key=").append(key).append("&token=").append(token);

Remember that you need to use PUT instead of POST.