Using Marketo ID inside of a token | Community
Skip to main content
Level 2
May 6, 2025
Solved

Using Marketo ID inside of a token

  • May 6, 2025
  • 1 reply
  • 1264 views

I've built an email where most of the content is generated inside of a script token. This token uses a For Loop (and information from the customer's profile) to generate a bunch of CTA's that the customer can click on. This all works fine; I just needed to explain that the For Loop inside the token is vital to the email's construction.

Here's the problem: The CTA's created inside of this loop needs to pass the customer's Marketo ID as a way to identify them(something like "website.com/?mID=(Marketo  ID"). I found that I can drop {{Lead.ID}} straight into the email body and it will display the number no problem. However, using that same code inside a token doesn't work. The result is "website.com/?mID={{Lead.ID}}".

Next I tried declaring it as a variable inside of a token. I check the box next to "Marketo ID", wrote "#set( $m_ID = ${lead.marketoID}) at the top of my token, and then wrote the URL into the token as "website.com/?mID=${m_ID}." The end result is the link looking like "website.com/?mID=" with no ID or even the variable name.

It seems silly to me that there wouldn't be a way to include Marketo ID in a token, but I just can't find a way to do it. Is there a way to do what I'm describing? If there's a better way to ID someone via a URL parameter for use on another website, I'm all ears.

Best answer by SanfordWhiteman

Next I tried declaring it as a variable inside of a token. I check the box next to "Marketo ID", wrote "#set( $m_ID = ${lead.marketoID}) at the top of my token, and then wrote the URL into the token as "website.com/?mID=${m_ID}." The end result is the link looking like "website.com/?mID=" with no ID or even the variable name.

Don’t think that field is a standard field. It’s probably custom if you look in Field Management. Perhaps it was intended to mirror the Lead ID (via Change Data Value) but the corresponding smart campaign wasn’t set up.

 

In any case, setting an intermediate variable will never change anything. If the right-hand side of a #set exists, you could use also that expression directly; if not, you can’t make it exist.

 

Anyway, here’s how to get more information about the send context, including the Lead ID. Pretty sure this still works:

#set( $marketoSend = {} ) #set( $delim = ":|-" ) #set( $values = $mktmail.xMarketoIdHdr.split($delim) ) #set( $numParts = $values.size() ) ## Campaign Run ID not relevant in Preview, Test Variant not always present, etc. #set( $keyTemplatesBySize = { 13 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId--TestVariantId", 12 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId-", 11 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId", "*" : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::LeadId" } ) #set( $marketoIdKeys = $display.alt($keyTemplatesBySize[$numParts],$keyTemplatesBySize["*"]) ) #set( $keys = $marketoIdKeys.split($delim) ) ## loop interesting keys #foreach( $key in $keys ) #if( !$key.isEmpty() ) #if( $key.startsWith("+") ) #set( $finalKey = $key.substring(1) ) #set( $marketoSend[$finalKey] = $marketoSend[$finalKey] + "-" + $values[$foreach.index] ) #else #set( $finalKey = $key ) #set( $marketoSend[$finalKey] = $values[$foreach.index] ) #end #end #end Munchkin ID is ${marketoSend.MunchkinId} Campaign ID is ${marketoSend.CampaignId} Campaign Run ID is ${marketoSend.CampaignRunId} Step ID is ${marketoSend.StepId} Asset ID is ${marketoSend.AssetId} Lead ID is ${marketoSend.LeadId} Test Variant ID is ${marketoSend.TestVariantId}

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
May 6, 2025

Next I tried declaring it as a variable inside of a token. I check the box next to "Marketo ID", wrote "#set( $m_ID = ${lead.marketoID}) at the top of my token, and then wrote the URL into the token as "website.com/?mID=${m_ID}." The end result is the link looking like "website.com/?mID=" with no ID or even the variable name.

Don’t think that field is a standard field. It’s probably custom if you look in Field Management. Perhaps it was intended to mirror the Lead ID (via Change Data Value) but the corresponding smart campaign wasn’t set up.

 

In any case, setting an intermediate variable will never change anything. If the right-hand side of a #set exists, you could use also that expression directly; if not, you can’t make it exist.

 

Anyway, here’s how to get more information about the send context, including the Lead ID. Pretty sure this still works:

#set( $marketoSend = {} ) #set( $delim = ":|-" ) #set( $values = $mktmail.xMarketoIdHdr.split($delim) ) #set( $numParts = $values.size() ) ## Campaign Run ID not relevant in Preview, Test Variant not always present, etc. #set( $keyTemplatesBySize = { 13 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId--TestVariantId", 12 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId-", 11 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId", "*" : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::LeadId" } ) #set( $marketoIdKeys = $display.alt($keyTemplatesBySize[$numParts],$keyTemplatesBySize["*"]) ) #set( $keys = $marketoIdKeys.split($delim) ) ## loop interesting keys #foreach( $key in $keys ) #if( !$key.isEmpty() ) #if( $key.startsWith("+") ) #set( $finalKey = $key.substring(1) ) #set( $marketoSend[$finalKey] = $marketoSend[$finalKey] + "-" + $values[$foreach.index] ) #else #set( $finalKey = $key ) #set( $marketoSend[$finalKey] = $values[$foreach.index] ) #end #end #end Munchkin ID is ${marketoSend.MunchkinId} Campaign ID is ${marketoSend.CampaignId} Campaign Run ID is ${marketoSend.CampaignRunId} Step ID is ${marketoSend.StepId} Asset ID is ${marketoSend.AssetId} Lead ID is ${marketoSend.LeadId} Test Variant ID is ${marketoSend.TestVariantId}

 

Mx_BrazeAuthor
Level 2
May 7, 2025

Oh wow, that did the trick! I swear, it's never straight forward to do the things I want in Marketo.

Thanks SanfordWhiteman! Your knowledge is always appreciated. For real though, Adobe should pay you to rewrite all of their documentation. Whenever I can't find an answer there, it seems you've already figured it out here.

SanfordWhiteman
Level 10
May 7, 2025

The tricks are the trade, yes!