falafelocelot
falafelocelot

Reputation: 588

Issue with Trello webhook

I'm currently working with Trello's API and I'm trying to set a webhook, but I'm running into issues that hopefully someone can help me resolve. First of all in the Trello API and docs (https://trello.com/docs/gettingstarted/webhooks.html), creating a webhook requires sending the idModel as part of the JSON. I guess my first problem is that I'm not sure exactly sure what the idModel, or how I can find this id. I tried to use the id I get if I get tokens, but currently I'm getting a 400 response error when I send a request to the following endpoint:

https://trello.com/1/tokens/daf73f1c77efc8f6062aaa94005ab07215d8d390ff2caffe57659707fee32597/webhooks

and my JSON looks something like (replace callbackURL with my actual callback URL):

{
 description: "My first webhook",
 callbackURL: callbackURL,
 idModel: "54fdef9430a36282010f6230",
}

Upvotes: 2

Views: 5499

Answers (3)

doykle
doykle

Reputation: 127

I had this issue also and found this question where the solution was to add a Content-Type header to the request. Adding the header "Content-Type": "applicaton/json" worked for me.

Upvotes: 0

Itai Soudry
Itai Soudry

Reputation: 350

plingamp is right. but notice you have an extra , in your JSON body.

it should look like

{
 description: "My first webhook",
 callbackURL: callbackURL,
 idModel: "54fdef9430a36282010f6230"
}

I suggest you use Postman for this one. Use a POST request with a raw JSON body, and with the same parameters as you did before. it should work if the user token and app key are correct (just copy the body I wrote here ), I had the same issue exactly and it worked out.

Also, use request bin and copy the link as the callBackUrl and you will be able to see the POST request made by trello.

Upvotes: 0

plingamp
plingamp

Reputation: 143

To answer your first question, the idModel is the object that you want to monitor. This can be a card, list, board etc.

Get the ids for the lists on a board using the following end point: https://api.trello.com/1/boards/[boardID]/lists?key=[App-key]&token=[App-token]

Then use one these ids to monitor a list for changes.

I think the reason you might be getting a 400 error is that you are not passing a key to the web hook creation endpoint.

You have to send a POST request to the endpoint like this:

curl \ 
-H "Content-Type: application/json" \
-d '{"description": "My First Webhook",
"callbackURL": "http://www.mywebsite.com/trelloCallback",
"idModel": "4d5ea62fd76aa1136000000c"}'
 https://trello.com/1/tokens/[USER_TOKEN]/webhooks/?key=[APPLICATION_KEY]

Note that when you make this POST request to create the webhook, Trello will make a HEAD request to your server, and they will expect your server to respond with a 200 status.

Upvotes: 6

Related Questions