For those who are adding webhooks to a board through the API (e.g. in a subscribe event from a custom trigger) take care: lot of escaping to do!
I use a function like below to inset any type of webhook to a board and returns the trigger Id. (forgive the formatting, not the best editor here
static async createWebhook(token, boardId, webhookUrl, webhookType) {
try {
const mondayClient = initMondayClient();
mondayClient.setToken(token);
const query =
mutation create_webhook($boardId: Int!, $webhookUrl: String!) { create_webhook(board_id: $boardId, url: $webhookUrl, event:
+
webhookType +
) { id } }
;
const variables = { boardId, webhookUrl };
const response = await mondayClient.api(query, { variables });
return response.data.create_webhook.id;
} catch (err) {
console.log(err);
}
}
This function is called like this for an add_item webhook, with a token, a boardId, a webhookUrl (I my specific case I needed the host part dynamic) and a webhookType.
const triggerHooks = await mondayService.createWebhook(
token,
boardId,
“https://” + req.headers.host + “/vote-to-group/webhookaction”,
“change_column_value”
);
Now, for the change_specific_column_value webhook you can still use the same function but take care of all the escaping done for the last argument (webhookType). All the \ characters in the last argument are really double-backslashes (\\) but lost in this code editor. At least in VSCode you need to escape the escape character
const triggerHooks = await mondayService.createWebhook(
token,
boardId,
“https://” + req.headers.host + “/vote-to-group/webhookaction”,
‘change_specific_column_value config: “{\“columnId\”:\”’ + columnId + ‘\“}”’
);
Many thanks to @ptsgJason for this find and happy webhooking