Hi Community,
I need to create a dynamic token that i can pass via an webhook to an external system, in webhooks i have tried inserting tokens including: email script (velocity) as well as text (static), here static works fine when the call is made but not the velocity script.
for e.g.:
I created an Smart campaign where it triggers the webhook to call an external API with certain details like: Lead Name, Id, program name etc. For that i have created tokens and tried passing onto the webhook, it works but not exactly as expected.
Velocity Script:
#if( $lead.FirstName.equals("[Not Defined]") || $lead.FirstName.isEmpty() )
Hi there!
#else
Hi $lead.FirstName!
#end
It translated to:
{"codeBlock":"#if( $lead.FirstName.equals(\"[Not Defined]\") || $lead.FirstName.isEmpty() )\nHi there!\n#else\nHi $lead.FirstName!\n#end","scriptingObjects":{"standard":{"2":{"label":"Person","fields":{"28":{"label":"First Name"},"128":{"label":"Country"}}}}}}
Solved! Go to Solution.
I've replied in your colleagues thread (I'm assuming the other post with the same block of code is from your colleague), but, velocity tokens don't work outside of emails.
For you to achieve what you need, which is conditionally changing the greeting depending on the first name value...
can you not code the logic into the receiving service?
alternatively, create a handler in the middle to execute the conditional logic and on-forward the payload to the final endpoint.
lastly, depending on how complex your final solution is supposed to be, you can have various versions of hard coded webhooks where a smart campaign can do the routing
Yep, like Jay mentions in his (correct) answer, if you already have a remote service expecting a JSON (i.e. non-executable) payload, one would hope that service could do whatever transformation you need.
If this isn't possible because the service is operated by a 3rd party, then consider calling an API gateway instead for these types of on-the-fly transforms.
I've replied in your colleagues thread (I'm assuming the other post with the same block of code is from your colleague), but, velocity tokens don't work outside of emails.
For you to achieve what you need, which is conditionally changing the greeting depending on the first name value...
can you not code the logic into the receiving service?
alternatively, create a handler in the middle to execute the conditional logic and on-forward the payload to the final endpoint.
lastly, depending on how complex your final solution is supposed to be, you can have various versions of hard coded webhooks where a smart campaign can do the routing
Yep, like Jay mentions in his (correct) answer, if you already have a remote service expecting a JSON (i.e. non-executable) payload, one would hope that service could do whatever transformation you need.
If this isn't possible because the service is operated by a 3rd party, then consider calling an API gateway instead for these types of on-the-fly transforms.
Thanks @SanfordWhiteman the service is indeed operated by a 3rd party which accepts the JSON only in a particular format and hence we are now using Mulesoft for the transformations before sending it.