Trello API - Adding a label deletes all existing

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