Adding custom variable to webhook API

Gaurav Srivastava June 28, 2020

Hi Team,

I have integrated Salesforce and Trello using Trello API. Currently when a record is created in Salesforce trello creates card for the same from Trello API. Webhook is active for the board. If Trello user create new card in trello callbackurl is called in salesforce to receive the json from webhook to check the type and if it 'createCard' then it create record in salesforce. Now the issue comes when Salesforce creates the card from Trello API and Trello assumes card to be created manually and fires webhook and salesforce ends up creating same duplicate record. I was looking if we have any custom parameter in the webhook json to difference if that card is created from API or manually?  

 

Thanks,

Gaurav

3 answers

0 votes
milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 1, 2020

@Gaurav Srivastava

above is end result

@Gaurav Srivastava you are right. As you do not integrate SF into an empty board..best to setup the board first

 

trello_card = client.get_card('5efc55a5b9233223b368767a')
board = client.get_board(trello_card.board.id)

print(trello_card.labels)
print('board name : ', board.name)
print('card name : ',trello_card.name)
print('labels defined on board', board.get_labels())
print('*******\n\n')
board.add_label(name = 'Wayscript', color = 'purple')
print('labels defined on board', board.get_labels())
print('*******\n\n')
trello_card.create_label(name='Trello_Card', color = 'red')
print('labels defined on board', board.get_labels())
print('*******\n\n')
for label in board.get_labels():
if label.name == 'Wayscript':
trello_card.add_label(label)

Python Log

None
board name :  Wayscript - Trello Demo
card name :  Salesforce Test Card
labels defined on board []
*******


labels defined on board [<Label Wayscript>]
*******


labels defined on board [<Label Trello_Card>, <Label Wayscript>]
*******

 

Gaurav Srivastava July 1, 2020

@milynnus @Iain Dooley Since there was no label field returned from webhook json, I ended up calling below GET request to get label field from card.

GET /1/cards/{id}/{field}

As soon as webhook is triggered, I took created card Id and checked if label exists or not. If not then card is created from trello else from its created from trello.

Appreciate your help :)

0 votes
Iain Dooley
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2020

@Gaurav Srivastava

when you create the card automatically using the API post it with an idLabels parameter set to some label like “Salesforce” then only create the sales force record if the created card doesn’t have this label 

milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2020

@Gaurav Srivastava agree with @Iain Dooley  use of label will be eye catching. Regardless, there has to be logic to differentiate between machine and man, if that is your goal. Not difficult. Just have to come up with a scheme. In the trigger panel you can see that there is enough for you to work with once the trigger detects a createCard action. 

Gaurav Srivastava July 1, 2020

@milynnus @Iain Dooley 

Thank you team! I tried this earlier  but unfortunately it doesn't work in my case of webhook response.

I see there are two ways for assigning label to card.
1. Create card and then call another API to set label on card.
2. Create label on board and then while creating card assign label Id to card.

In first case the card will be created first and webhook will be fired without label so doesn't work.

In second case, if I create label on board and then assign on card, then in webhook response I don't see label field returned. It returns LabelNames for Board which is present across all cards irrespective of card created from API (Salesforce) or manually.

Below is the response from webhook when created from Trello.

{Code}
{
"model":{
"id":"5efc1e73a8e90177259ab4a3",
"name":"BSR - Data Migration (E00301)",
"desc":"",
"descData":null,
"closed":false,
"idOrganization":null,
"idEnterprise":null,
"pinned":false,
"url":"https://trello.com/b/u6w1xCv/bsr-data-migration-e00301",
"shortUrl":"https://trello.com/b/u6w1xCKv",
"prefs":{
"permissionLevel":"private",
"hideVotes":false,
"voting":"disabled",
"comments":"members",
"invitations":"members",
"selfJoin":true,
"cardCovers":true,
"isTemplate":false,
"cardAging":"regular",
"calendarFeedEnabled":false,
"background":"blue",
"backgroundImage":null,
"backgroundImageScaled":null,
"backgroundTile":false,
"backgroundBrightness":"dark",
"backgroundColor":"#0079BF",
"backgroundBottomColor":"#0079BF",
"backgroundTopColor":"#0079BF",
"canBePublic":true,
"canBeEnterprise":true,
"canBeOrg":true,
"canBePrivate":true,
"canInvite":true
},
"labelNames":{
"green":"",
"yellow":"",
"orange":"",
"red":"",
"purple":"",
"blue":"",
"sky":"",
"lime":"",
"pink":"",
"black":"Kimble Originated"
}
},
"action":{
"id":"5efc3ec20492d077e20a45e8",
"idMemberCreator":"5e495130215e22480cf63c3a",
"data":{
"card":{
"id":"5efc3ec20492d077e20a45e7",
"name":"second",
"idShort":11,
"shortLink":"CNAK3gfe"
},
"list":{
"id":"5efc1e7581f64b37224ec4cc",
"name":"Sprint 1API test"
},
"board":{
"id":"5efc1e73a8e90177259ab4a3",
"name":"BSR - Data Migration (E00301)",
"shortLink":"u6w1xCKv"
}
},
"type":"createCard",
"date":"2020-07-01T07:44:02.228Z",
"limits":{

},
"display":{
"translationKey":"action_create_card",
"entities":{
"card":{
"type":"card",
"id":"5efc3ec20492d077e20a45e7",
"shortLink":"CNAK3gfe",
"text":"second"
},
"list":{
"type":"list",
"id":"5efc1e7581f64b37224ec4cc",
"text":"Sprint 1API test"
},
"memberCreator":{
"type":"member",
"id":"5e495130215e22480cf63c3a",
"username":"gauravsrivastava64",
"text":"Gaurav Srivastava"
}
}
},
"memberCreator":{
"id":"5e495130215e22480cf63c3a",
"username":"gauravsrivastava64",
"activityBlocked":false,
"avatarHash":null,
"avatarUrl":null,
"fullName":"Gaurav Srivastava",
"idMemberReferrer":null,
"initials":"GS",
"nonPublic":{

},
"nonPublicAvailable":true
}
}
}
{code}


Below is the response from webhook when created from Trello.

{Code}
{
"model":{
"id":"5efc1e73a8e90177259ab4a3",
"name":"BSR - Data Migration (E00301)",
"desc":"",
"descData":null,
"closed":false,
"idOrganization":null,
"idEnterprise":null,
"pinned":false,
"url":"https://trello.com/b/u6w1xCKv/bsr-data-migration-e00301",
"shortUrl":"https://trello.com/b/u6w1xCKv",
"prefs":{
"permissionLevel":"private",
"hideVotes":false,
"voting":"disabled",
"comments":"members",
"invitations":"members",
"selfJoin":true,
"cardCovers":true,
"isTemplate":false,
"cardAging":"regular",
"calendarFeedEnabled":false,
"background":"blue",
"backgroundImage":null,
"backgroundImageScaled":null,
"backgroundTile":false,
"backgroundBrightness":"dark",
"backgroundColor":"#0079BF",
"backgroundBottomColor":"#0079BF",
"backgroundTopColor":"#0079BF",
"canBePublic":true,
"canBeEnterprise":true,
"canBeOrg":true,
"canBePrivate":true,
"canInvite":true
},
"labelNames":{
"green":"",
"yellow":"",
"orange":"",
"red":"",
"purple":"",
"blue":"",
"sky":"",
"lime":"",
"pink":"",
"black":"Kimble Originated"
}
},
"action":{
"id":"5efc422050d51e08558d2d97",
"idMemberCreator":"5e495130215e22480cf63c3a",
"data":{
"card":{
"id":"5efc422050d51e08558d2d96",
"name":"Created from Salesforce",
"idShort":14,
"shortLink":"p4il2cKr"
},
"list":{
"id":"5efc1e7581f64b37224ec4cc",
"name":"Sprint 1API test"
},
"board":{
"id":"5efc1e73a8e90177259ab4a3",
"name":"BSR - Data Migration (E00301)",
"shortLink":"u6w1xCKv"
}
},
"type":"createCard",
"date":"2020-07-01T07:58:24.115Z",
"limits":{

},
"display":{
"translationKey":"action_create_card",
"entities":{
"card":{
"type":"card",
"id":"5efc422050d51e08558d2d96",
"shortLink":"p4il2cKr",
"text":"Created from Salesforce"
},
"list":{
"type":"list",
"id":"5efc1e7581f64b37224ec4cc",
"text":"Sprint 1API test"
},
"memberCreator":{
"type":"member",
"id":"5e495130215e22480cf63c3a",
"username":"gauravsrivastava64",
"text":"Gaurav Srivastava"
}
}
},
"memberCreator":{
"id":"5e495130215e22480cf63c3a",
"username":"gauravsrivastava64",
"activityBlocked":false,
"avatarHash":null,
"avatarUrl":null,
"fullName":"Gaurav Srivastava",
"idMemberReferrer":null,
"initials":"GS",
"nonPublic":{

},
"nonPublicAvailable":true
}
}
}
{Code}

0 votes
milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2020

@Gaurav Srivastava The platform that I been investigating has a Salesforce module and Trello modules and Triggers (board, list and card). While I have not worked on Salesforce, I have used the Trello modules and triggers. I used it in conjunction with py-trello library.

This is something I posted today https://youtu.be/vuu4nJ8ET4Y

In the situation you described, and if I am using the triggers I have I would probably have to check the Changer Name/Username. You will have to design this to your webhook.

Gaurav Srivastava June 29, 2020

@[deleted] Currently webhook is called from Salesforce for a board. So when I create card webhook is fired and returns me json data for same card. Can we add custom variable when we are creating card from API so that in response json we can see custom variable and operates based on that?

Gaurav Srivastava June 29, 2020

@Iain Dooley Hope you are well lain! Any suggestion on this?

milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2020

Will try to show you how I can do it with a demo. 

Like Gaurav Srivastava likes this
milynnus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2020

Hope this help clarifies

https://youtu.be/pQaAqzR-5Sw

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events