In the previous post, I described a poster child for automation: managing the repetitive tasks around a conference submission workflow. I wrote about the setup, and how to use
ngrok
to redirect webhooks to my computer. This week, I’d like to write about some of the hiccups I encountered along the way.Most SaaS providers allow to register webhooks through their GUI. This is the case of GitHub for example: it’s located in the Settings > Webhooks menu.
For better or worse, this is not the case of Trello. To register a webhook, one needs to execute an HTTP request. This requires:
{
"id": "5d383691a3aeaa3b5741953d",
"name": "My board",
"desc": "",
"descData": null,
"closed": false,
"idOrganization": null,
"idEnterprise": null
}
curl -X POST -H "Content-Type: application/json" \
https://api.trello.com/1/tokens/{token}/webhooks/ \
-d '{
"key": "{key}",
"callbackURL": "http://www.mywebsite.com/trelloCallback",
"idModel":"{boardID}",
"description": "Name of the webhook"
}'
To check the webhook is valid, Trello will immediately send a
HEAD
The
HEAD
HTTP method is rarely used. For example, when using Spring Boot, it requires explicitly configuring such an endpoint:fun routes(runtimeService: RuntimeService) = router {
val handler = TriggerHandler(runtimeService)
POST("/trigger", handler::post)
HEAD("/trigger", handler::head)
}
class TriggerHandler(private val runtimeService: RuntimeService) {
fun post(request: ServerRequest): ServerResponse {
// Starts the workflow instance
}
fun head(request: ServerRequest) = ServerResponse.ok().build()
}
The above snippet isn’t very compliant with the HTTP specifications as the controller doesn’t offer any
GET
endpoint':The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.
— Hypertext Transfer Protocol -- HTTP/1.1
https://ietf.org/rfc/rfc2616.txt
In all cases, it gets the job done. Besides, I didn’t find any way to easily create a
HEAD
endpoint that delegates to a GET
endpoint. Hints are more than welcome. Google requires permission to manage objects: read, write, etc. The problem with the most recent documentation, whether on Calendar or Sheets (or any other Google API), is that it’s skewed toward Android e.g. Calendar Java Quickstart. In such a use-case, the request for permission is interactive: the user is first presented with a authenticate screen, and then asked to give the required permission.
Workflows in general allow for interactive or automated steps. An interactive step allows to enter one’s credentials and authorize the app, but the previously-defined workflow only has automated steps. For a truly
automated workflow, interactive steps should be avoided if possible.
However, Google prevents to use one’s account credentials - login and
password - for security reasons. But it provides an alternative: one can
create a so-called service account, and give it write permissions to
the relevant calendar and documents.
Creating a Google service account
To create a service account:
Configuring permissions
To give the service account access to one’s calendar (or documents) requires two steps:
While the previous post described the context behind automating a workflow, this post lists the necessary configuration steps: the Trello webhook and the Google service accounts. While nothing out-of-the-ordinary, it takes time to research the above facts if one doesn’t know about them previously.
To go further:
Previously published at A Java Geek on May 17th, 2020