Custom Tokens for a Webhook

Highlighted
Anonymous
Not applicable

Custom Tokens for a Webhook

Hi all,

We need to create a custom token with custom object fields in order to push this data by a webhook.

We're trying to preserve our API quota. Is this possible?

I'm able to create an email script token to pull in the fields but it's only at program level. Am I doing this wrong?

7 REPLIES 7
Highlighted
Level 10 - Community Moderator

Re: Custom Tokens for a Webhook

You can't use Velocity tokens directly in webhooks, as you've found. I recommend you use JSON text fields instead of Custom Objects (in many ways JSON is more powerful, since your "poor man's" COs can then be accessed on LPs as well).

FlowBoost Pro has what we call Floxy (FlowBoost Proxy) that does allow real COs to be passed to external services, but it's better to avoid the need entirely.

Highlighted
Level 1

Re: Custom Tokens for a Webhook

Hi Sanford Whiteman,

I am trying to scale a system where we have VTL script tokens in the JSON for an endpoint that we call on click of an email that is within the campaign where those VTL tokens reside.

Are you saying that these tokens will not resolve within the flow step that calls the webhook for each contact that clicks?

Excerpt of the JSON:

{

"perk": {

"name": {{my.promoPerk1}},

"num_days_active": {{my.daysActive}}

},

"message": {{my.promoMessage}},

...

}

my.promoPerk1 is a VTL script token in the campaign as is my.promoMessage.

Scripting for my.promoPerk1

#set ($vertical = ${Product_Metric__cList.get(0).Vertical__c}) ## Salesforce object

#set ($perk = "")

#define ($beautySpa)

20% off all services

#end

#define ($food)

20% off one main dish

#end

#define ($shopping)

25% off one full price item

#end

#define ($default)

20% entire purchase

#end

#if ($vertical == "Beauty & Spa")

#set ($perk = $beautySpa)

#elseif ($vertical == "Food")

#set ($perk = $food)

#elseif ($vertical == "Shopping")

#set ($perk = $shopping)

#else

#set ($perk = $default)

#end

$perk

I think my other option is to make one campaign for each vertical that we target and use text tokens for each value (instead of script tokens). I know that will work it is just not as clean and takes a lot more time to set up when we want to do one of these campaigns.

Thanks for any help!

Highlighted
Level 10 - Community Moderator

Re: Custom Tokens for a Webhook

Are you saying that these tokens will not resolve within the flow step that calls the webhook for each contact that clicks?

Yes: Velocity is evaluated in an email assembly context (including View as Web Page) only.

P.S. Careful with that use of formal notation in the first line. You can use simple notation there (only use formal when proven necessary).

Highlighted
Level 1

Re: Custom Tokens for a Webhook

That is a bummer.

Will it work if the VTL referenced a Rich Text (or just Text) token and I controlled for vertical on the flow steps to call the appropriate hook?

Something like:

#set ($vertical = $Product_Metric__cList.get(0).Vertical__c)

#set ($perk = "")

#define ($beautySpa)

{{my.textToken1}}

#end

#define ($default)

{{my.textToken2}}

#end

#if ($vertical == "Beauty & Spa")

#set ($perk = $beautySpa)

#else

#set ($perk = $default)

#end

$perk

I'd then replace the script token reference in the JSON with the my.textTokenN (where N is the token associated with the correct vertical).

It'll mean, potentially, a lot more webhooks but I'd rather scale there than launch a separate campaign for each vertical we are targeting.

Also, thanks for the notation tip.

Highlighted

Re: Custom Tokens for a Webhook

those my tokens won't render as anything other than the literal "{{my.textToken1}}"

Highlighted
Level 10 - Community Moderator

Re: Custom Tokens for a Webhook

Believe it or not , there is a way to do this: so the Text {{my.token}} is valid JSON and can be used in Velocity as a live object (HashMap/ArrayList). I'd rather show you offline than dump the crazy method here, though. You know my email...

Highlighted
Level 3

Re: Custom Tokens for a Webhook

Hi @Sanford, I am trying to perform a similar action where we would use Velocity Scripting in a Text Message. Was wondering if you could help out.