I am trying to delete a card's label on trello and am getting "invalid key" as response from trello api.
my apikey, token, card ID and labelID are correct I have checked against their documentation, where you can input these and try.
my code is the same as on their documentation:
var optionsDeleteLabel = {
method: 'DELETE',
url: `https://api.trello.com/1/cards/${body[i].id}/idLabels/${greenLabelId}&key=${apiKey}&token=${token}`,
};
request(optionsDeleteLabel, function(error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
what could I be doing wrong?
Thank you everybody, for the comments on my question.
Indeed I have found the problem and the solution. When I was getting the body[i].id , it was not getting parsed correctly (I was using JSON.stringfy and it was giving me with quotes), resulting in URL of the request being incorrect (the card ID in the URL had quotes). Trello was responding invalid key because the URL was not referring to the resource I was trying to reach, but to another...
the solution was to use
JSON.stringify(body[i].id).replace(/\"/g, "")
to get a new variable which I have used to make the URL without the quotes before and after the card id