Trello API - Adding a label deletes all existing

I’ve tested using the below REST command. This adds the requested label, but deletes all others on the card. What’s up with this?

curl --request PUT --url “https://api.trello.com/1/cards/629b99961aba6621a965af3d?key=&token=&pos=top&idLabels=5f9454063d0e0a1fe63fb58f” --header “Accept: application/json”

I think it’s because you’re using the update card end point and not the add a label to card end point.

Hmm, Will take a look. Thanks so much.

I’m really confused now. Below is the documentation from Trello’s " Add a Label to a Card". There’s no place to add the ID of the label to be added.

curl --request POST
–url ‘https://api.trello.com/1/cards/{id}/idLabels?key=APIKey&token=APIToken

The Trello REST API (atlassian.com)

Look closely at the “query parameters”. It doesn’t show up in the example for some reason.

I’m wondering if this is a bug in the api… I would think the add and delete commands should work the same way.
This works fine:
curl --request DELETE --url “https://api.trello.com/1/cards/629e3e010ae1e7152f3d971e/idLabels/5c92632a91d0c2ddc590b2a0?key=mykey&token=mytoken” --header “Accept: application/json”

As I stated above, I think the API documnetaion is incorrect. I would think the similar syntax for adding a label should work, but it doesn’t

curl --request POST --url “https://api.trello.com/1/cards/629e3e010ae1e7152f3d971e/idLabels/5c92632a91d0c2ddc590b2a0?key=mykey&token=mytoken” --header “Accept: application/json”

The returned message is “Can not POST”.

The Add a label to a card endpoint works if you use this method:

POST https://api.trello.com/1/cards/{{TrelloCardId}}/idLabels

with this body:

{
    "value" : "602786e986c6bc9cc552377d", -- The ID of an existing label
    "key" : "{{TrelloKey}}",
    "token" : "{{TrelloToken}}"
}

Alternatively, you can use this single URL:

POST https://api.trello.com/1/cards/{{TrelloCardId}}/idLabels?value="602786e986c6bc9cc552377d&key={{TrelloKey}}&token={{TrelloToken}}"

Yes, it can seem strange that the Add label and Remove label endpoints work in a dissimilar manner for how the ID of the label is passed in the request (using a path parameter versus a query parameter), but all Trello’s POST and DELETE methods use that same logic.

I personally never try to refer to labels by their IDs, as it’s barbaric :wink:. I much prefer to just use a label’s name + color.

  • If I use a name + color of an existing label, then that label is applied.
  • If I use a new name + color, then that new label is created first, then applied.

I use this method:

POST https://api.trello.com/1/cards/{{TrelloCardId}}/labels

with this body:

{
    "name" : "The new or existing label",
    "color" : "green",
    "key" : "{{TrelloKey}}",
    "token" : "{{TrelloToken}}"
}

For some reason, this method is no longer described on the REST API documentation page. Perhaps it’s a precursor that the ability to add a label using this method will be deprecated, and adding labels by their ID will be the only method in the future?

1 Like

I did get this to work, but ran into another issue. If you add a card using this method then all existing cards are deleted. I’m still working on this. Just now reading through a post from Mr. Banning. Seeking Trello API Developer - .net C# - Trello - The Atlassian Developer Community

@GlennWilliams

You are talking about something completely different now. Adding cards has nothing to do with adding labels to cards.

Also, if my answer was correct, can you please mark it as such.

PS. I think someone is publishing new Trello REST API documentation, as I’ve found another instance where a previous text based parameter has been replaced by ID based parameter that doesn’t seem to work as advertised (refer to this question) and other documentation elsewhere contradicts the new documentation.

Holy cow. I said cards, meant labels.
If you add a label using this method then all existing labels are deleted

@GlennWilliams
I cannot replicate that issue. For me, the Add a label to a card endpoint is working exactly as expected.