Beeminder Forum

Request: Live Trello Updates (Webhooks)


#1

Live updates of trello goals pretty please? For us skate the YBR people. Currently the Beeminder bot pretends that nothing happened in Trello land until right on the deadline.
So logically the bot shouts at you constantly because supposedly you ain’t doing anything from its point of view.

Have a look at this:

we have built a system that allows your application to hook into updates on various members such as Boards, Lists, and Cards. Whenever a member with a Webhook is changed, we make an HTTP request to the endpoint of your choosing.

More about that: https://developers.trello.com/page/webhooks

Also in case this didn’t exist when you made the Trello integration in the first place: https://developers.trello.com/docs/clientjs


#2

What happens if you hit refresh in a Trello goal, rather than waiting for autodata to grab on its own schedule?


#3

Then it grabs the data as expected. While this certainly helps to calm the bot, I don’t want to have to do this.
And the webhooks api looks really nice :upside_down_face:


#4

I couldn’t resist, went ahead and made this. I’m a bit surprised it was that easy (33 minutes), but the trello API documentation is excellent and so is the Beeminder API documentation. Together with the really nice vs code REST client extension I quickly hacked together something that does trigger a data fetch via webhook:

Code
@APIKey = your_trello_api_key
@APIToken = your_trello_api_token
@tbase = https://api.trello.com/1

@bbase = https://www.beeminder.com/api/v1
@bauth = your_beeminder_auth_token
@u = your_user
@g = your_slug
@refresh = {{bbase}}/users/{{u}}/goals/{{g}}/refresh_graph.json?auth_token={{bauth}}

### Get trello boards
# @name getBoards
GET {{tbase}}/members/me/boards?key={{APIKey}}&token={{APIToken}}

### Now we got the id of the relevant board
@spihtId = {{getBoards.response.body.$[?(@.name=='your_board_name')].id}}

# @name createHook
POST {{tbase}}/tokens/{{APIToken}}/webhooks/?key={{APIKey}} HTTP/1.1
Content-Type: application/x-www-form-urlencoded

description=refresh graph
&callbackURL={{refresh}}
&idModel={{spihtId}}

###

@hookId = {{createHook.response.body.$.id}}

### This gave us a hook
# which we can look at
GET {{tbase}}/tokens/{{APIToken}}/webhooks/{{hookId}}?key={{APIKey}} HTTP/1.1

### and finally delete again
DELETE {{tbase}}/tokens/{{APIToken}}/webhooks/{{hookId}}?key={{APIKey}} HTTP/1.1

### List all webhooks just to make sure we got them all
GET {{tbase}}/tokens/{{APIToken}}/webhooks/?key={{APIKey}} HTTP/1.1

Paste this into VS Code, throw this extension at it and you should be good.

Since the Beeminder API docs are very explicit about not doing this too often I included a snippet to delete the webhook again.
Ideally one would directly PUT the new data point value into Beeminder instead of merely telling the api to refresh. But hey for a good half an hour I’m quite pleased.


#5

The attentive reader might have already guessed that there is a slight problem with the slapdash code I posted POSTed.
But for those who did not GET it, here’s a quick rundown:
Trello sends web hooks using POST but Beeminder does not expect a POST for refreshing goals but a GET and only that. And that’s really all there is to it.

The upside is that in that POST Trello does actually provide a lot of details about what action triggered the hook. I’m pretty sure there’s everything in there that Beeminder would need to update the goal without it having to query anything else.

Obviously that’s another code path that needs implementing, testing, etc. but IF processing time and bandwidth ever are a concern then maybe this will compare favourably to simply refreshing the entire goal.