Trello: programmatic meta data on cards? Or is webhook X-Forwarded-For header reliable?
Asked by ali:

Use case: we have this situation where we trigger the creation of a trello card but it's linked to an entity in our system. So

e1 \<-\> card1

We also allow for cards to be created directly in trello and then implicitly create an entity in our system

card2 \<-\> e2

The problem is we need to inspect the webhook event for the second case, and it also comes back in the first case. So we need to distinguish the two cases.

So ideally, I want to store hidden meta data in the card. But afaik trello does not support this. So I noticed the X-Forwaded-For header is sent and it always has one the trello webhook-source IP addresses \[0\]. So can I rely on this?

Thanks for any help!

\[0\]: <https://developers.trello.com/page/webhooks#section-webhook-sources>


Answers:
author: ali
body: Thanks for the suggestions [@Iain Dooley](/t5/user/viewprofilepage/user-id/1416112) ! You are correct in what I want to do. The problem with the bot approach is as you mentioned, the user part. We still want case 1 (so e1 -\> card1) to be linked to the user that initiated it from the e1 side (we have a mapping from users in our system to your trello user, so the api request from e1-\>card1 is done on behalf of the user).

\> One option would be that if you're linking to an entity in your system, then you attach the link to the card as an attachment

Can you attach a comment on card creation? Because then this would work! I couldn't see that you could though. So you'd still get the web hook event with no comment in yet right?

comments: author: Iain Dooley
body: [@ali](/t5/user/viewprofilepage/user-id/3205425) you can't post with a comment, but you can create a new card with a link included which will be added to the card as an attachment:

<https://developers.trello.com/reference/#cards-2>

When you receive the notification, query the card to find out if there is a link to the entity in your system (just put your internal entity URL onto the card as an attachment) if the link exists, then this card was created by your system.

Otherwise, you can also post label IDs when creating the card, so you could have a system label like "Bot Created" (with no colour so it doesn't pollute your coloured label space) and likewise you can then query the API when you receive a card created webhook notification to confirm whether or not the card was created programatically or manually


author: ali
body: Yes! That works great! :D Thanks Iain.


author: Iain Dooley
body: [@ali](/t5/user/viewprofilepage/user-id/3205425) from what I understand you want to create a card in Trello programatically linked to an entity in your system, and allow users to create cards in Trello that will link to an entity in your system, but need to exclude events created when your system programatically creates the cards.

The way I resolve this is by using a "bot user". I created a G-Suite framework called Trellinator:

<https://community.atlassian.com/t5/Marketplace-Apps-articles/Introducing-Trellinator-Automate-Trello-with-Google-Apps-Script/ba-p/925271>

I use a method like this:

new Notification(notification).member().notTrellinator()

You can see the implementation here:

<https://github.com/iaindooley/trellinator-libs/blob/master/Member.js#L86>

Basically I just have a shortcut way of excluding things that have been done by the "bot". If you're not using a separate user to do the API calls, then it will be difficult to distinguish between actions taken by the team, and actions taken using a team member's API key programatically.

One option would be that if you're linking to an entity in your system, then you attach the link to the card as an attachment, then when you receive a card creation event after that, check to see if the link already exists on the card back to the entity in your system and if it does, assume that the card creation notification was a result of the card having been programatically created.


Tags: api

webhook