Link two boards using integration

Hi All,

I have created custom trigger to trigger my backend code when new update is created in source board.

So, when user install the integration on his board I will receive the installation event in my subscriber endpoint which is defined in custom trigger endpoints so i will create a new record in my backend DB and store the recipe selected options, webhook id, integration id, subscription id …etc and create webhook using API endpoint on source board.

So, when user create new update in source board, my code will be triggered and read the update to handle the event payload.

When user remove the integration from his source board I will remove the webhook from board using remove webhook API.

Everything working perfectly, but my issue when user install the integration more once same source board, Monday will add another “update was created” webhook on the same board, so I will get the event two times for same created update.

If I checked in my backend DB about this board is stored or not to doses not create webhook on it two times, I will not able to remove the created row which belongs to the removed integration because the unsubscription event provides me with webhookId only.

How i can prevent the webhook duplicate on same board when user install the integration more once on same board.

Or if i don’t needs to create webhook in each time user install the integration on his board how i can remove the recipe row from my backend DB when user remove it from monday.

I hope it was clear

Thanks

hi @f2yez
What you describe here is very close to how we build most of our integration apps. In the custom trigger subscribe endpoint we create webhooks (in whatever board we need) and store a config record in a local database. I see you store the webhook id (returned from the create_webhook API call) in your database. As this id is unique you can safely delete the record by that key in the unsubscribe event. In this way it will work perfectly fine for a single instance of the app per board.

When you want to be able to have multiple instances per board you need to do some additional checking. We do thati n the subscribe event (check if we have a record by (a set of) keys - make sure they are unique. In your use case I think the source boardid will be unique, or maybe you have to combine it with a columnid - depending on your recipes. If the record is found we simply do not create the webhook again. Same kind of logic is needed in the unsubscribe endpoint. Check is this recipe is “the last one on board” and if so, delete the webhooks.

Hope it make sense.

Ooh, I’m already made what you said, but I had miss understand in subscriptionId and webhookId.

Thanks!

Monday is using some confusing Id names at times :slight_smile: As you can see from below snippet I query my database on subscriptionId with the webhookId as parameter.

PS: I store the webhookIds (if I use multiple) as a string seperated by a pipe, hence the split method.

//Delete the webhook(s) used to trigger the webhookAction in case this is the last recipe.

const lastSubscription = await rollupMultipleBoards.lastSubscriptionOnBoard(accountId, webhookId);

const masterConfig = await rollupMultipleBoards.getMasterConfigBySubscription(webhookId);

if (lastSubscription && masterConfig) {

const triggerArray = masterConfig.triggerhooks.split("|");

triggerArray.forEach(function (triggerHook, index) {

  mondayService.deleteWebhook(shortLivedToken, parseInt(triggerHook));

});

}

1 Like

I didn’t understand the different between subscriptionId and webhookId because the subscribe function didn’t return webhookId and unsubscribe function return webhookId in response, some conflict was happened to me.

everythin now is working perfect, thanks a lot

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.