To connect the webhooks and APIs of Trello and Github, first we need to generate tokens on both side.
https://developer.github.com/webhooks/
Event Types & Payloads: https://developer.github.com/v3/activity/events/types/
Setup steps
Setup a GitHub webhook call to your server
-
Within your GitHub repository, go to settings.
-
In the left side navigation you'll find "Webhooks & Services".
-
Click "Add Webhook" Payload URL:
http(s)://<YOUR_DOMAIN>/github-hook (only accessable via POST)Content type:application/jsonSecret: random string, e.g.ThisIsAReallySafeAndSecretString!!11^!(Depending on your SSL certificate, disable the certificate check)Make sure you checked "Send me everything"
ℹ️ for debugging purposes, there's a second URL:
/github-hook/log -
Done; You should see a green check mark next to your new hook
To create an API token, follow those steps:
-
Go to your settings page https://github.com/settings/applications
-
Select "Applications" in the left sidebar
-
"Generate new token" Token description: e.g.
issue_managerSelect scopes: check at leastrepoorpublic_repo(depending on your repository type you want to link) -
Click "Generate token" and copy it to out parameters.yml
!! Make sure to copy your new personal access token now. You won't be able to see it again!
Before we can create a Webhook, we need an APPLICATION_KEY and a UserToken. Also we need to fetch the idModel of the board.
Generate an APPLICATION_KEY: https://trello.com/1/appkey/generate
To generate a read & write access token, open this URL in thw browser while being logged into your Trello account:
https://trello.com/1/authorize?key=<APPLICATION_KEY>&name=Issue+Manager&expiration=never&response_type=token&scope=read,write
You will receive a UserToken, save it.
Get the TRELLO_BOARD_SHORT_ID from the board URL
GET https://api.trello.com/1/board/<TRELLO_BOARD_SHORT_ID>?key=<APPLICATION_KEY>&token=<UserToken>
Will return a json, including id.
sample return JSON:
{"id":"26ca7070043c7581962930bb","name":"Development Features","desc":"","descData":null,"closed":false,"idOrganization":null,"pinned":false,"url":"https://trello.com/b/aQnT0luF/development-features","shortUrl":"https://trello.com/b/aQnT0luF","prefs":{"permissionLevel":"public","voting":"disabled","comments":"members","invitations":"members","selfJoin":false,"cardCovers":true,"cardAging":"regular","calendarFeedEnabled":false,"background":"grey","backgroundColor":"#808080","backgroundImage":null,"backgroundImageScaled":null,"backgroundTile":false,"backgroundBrightness":"unknown","canBePublic":true,"canBeOrg":true,"canBePrivate":true,"canInvite":true},"labelNames":{"green":"","yellow":"","orange":"","red":"","purple":"","blue":"","sky":"","lime":"","pink":"","black":""}}
Now we got the id aka idModel of the board.
Official setup documentation: https://trello.com/docs/gettingstarted/webhooks.html
Or follow those steps:
Before we can create a Webhook for a board, we need to get the idModel for the board.
Also, the webhook call URL on our side must be up and running (returning 200 OK on a HEAD request).
POST https://api.trello.com/1/tokens/<UserToken>/webhooks/?key=<APPLICATION_KEY> [application/json]
{
"description": "Issue Manager Webhook Logger",
"callbackURL": "https://<YOUR_DOMAIN>/trello-hook",
"idModel": "26ca7070043c7581962930bb"
}
With idModel being the id of the board.
Using curl:
curl 'https://api.trello.com/1/tokens/<UserToken>/webhooks/?key=<APPLICATION_KEY>' -H 'Content-Type: application/json' -H 'Accept: application/json' --data-binary $'{\n "description": "Issue Manager Webhook",\n "callbackURL": "https://issue-manager-demo.loopline-systems.com/trello-hook",\n "idModel": "26ca7070043c7581962930bb"\n}' --compressed
Return from Trello:
{
"id": "52cbfbb1aa3ecf483b7edc5b",
"description": "Issue Manager Webhook Logger",
"idModel": "26ca7070043c7581962930bb",
"callbackURL": "https://<YOUR_DOMAIN>/trello-hook",
"active": true
}
Save the idModel of the webhook! (will never be shown again)
Phew, we're done! Check your access logs, if the call worked.