Presented with minimal comment
Update 2019-07-10: Yeah, well… this was some awesome stuff and even used internally at Marketo, but after the June 2019 release it’s no longer possible. Preserving it for historical reference. (There’s another approach that has many similarities, but it’s the stuff of a future post.)
The below Velocity script copies a field from a Custom Object record to a Marketo Person field. Consider the possibilities.
#set( $flowBoostURL = "https://api.teknkl.com/flowboost_v17/run?authoringEnv=pro" )
#define( $flowBoostCode )
var munchkinId = "AAA-BBB-CCC",
clientId = "7N0VoUM45DXpbIFFyOVSshIz",
clientSecret = "ATHpPA9ByLNhmHn8G5cBXrCO";
var pushLeadObject = {
"programName" : "CO Survey 01",
"reason": "Copy latest CO CRM link",
"lookupField": "id",
"input": [
{
"id" : ${lead.leadID},
"website" : "${TriggerObject.crmLink}"
}
]
}
var mktoRESTBase = `https://${munchkinId}.mktorest.com`,
mktoRESTIdentity = `${mktoRESTBase}/identity/oauth/token` +
`?grant_type=client_credentials` +
`&client_id=${clientId}` +
`&client_secret=${clientSecret}`,
mktoRESTPushLead = `${mktoRESTBase}/rest/v1/leads/push.json`;
FBHttp.fetch(mktoRESTIdentity)
.then( resp => resp.json() )
.then( resp => resp.access_token )
.then( accessToken => {
var mktoHeaders = {
"Authorization" : `bearer ${accessToken}`,
"Content-Type" : "application/json"
};
return FBHttp.fetch(
mktoRESTPushLead, {
headers: mktoHeaders,
method: "POST",
body: JSON.stringify(pushLeadObject)
})
.then( resp => resp.json() )
.then(success);
})
#end
#set( $conn = $URL.newInstance($flowBoostURL).openConnection() )
#set( $void = $conn.setRequestMethod("POST") )
#set( $void = $conn.setRequestProperty("Content-Type","application/javascript") )
#set( $void = $conn.setRequestProperty("X-Api-Key","pro:0CA9d209t4fC6qTl5WXWimZb") )
#set( $void = $conn.setDoOutput(true) )
#set( $httpPayload = $DataOutputStream.newInstance($conn.getOutputStream()) )
#set( $void = $httpPayload.writeBytes($flowBoostCode.toString()) )
#set( $void = $httpPayload.flush() )
#set( $void = $httpPayload.close() )
HTTP Response: ${conn.getResponseCode()} ${conn.getResponseMessage()}