Webhook JSON response mapping - iterating values

Highlighted
Level 1

Webhook JSON response mapping - iterating values

Hi, 

I am working with Marketo webhooks. I need to map JSON response similar to below, where "orderDate" is to be mapped to a Marketo field. However, I need to get every "orderDate" from this response and compare it with the existing marketo field value. In case, if anyone has tackled this kind of scenario before, I can use some help.

{
"profileId" : 1234,
"firstName" : "Jane",
"lastName" : "Doe",
"orders" : [
{
"orderId" : 5678,
"orderDate" : "2015-01-01",
"orderProductId" : "4982"
},
{
"orderId" : 5672,
"orderDate" : "2014-05-07",
"orderProductId" : "4982"
},
{
"orderId" : 5673,
"orderDate" : "2014-03-02",
"orderProductId" : "4982"
}
]
}

Thanks in advance,

Asha Kamble

3 REPLIES 3
Highlighted
Level 10 - Community Moderator

Re: Webhook JSON response mapping - iterating values

Please edit your post & highlight the JSON (like all code) using the Advanced Editor's Syntax Highlighter.

When you say "compare it" -- to what end? Are you only trying to overwrite the value stored in Mkto if the value in the JSON is later, for example, taking the latest of the later values? Be exact: while it's very unlikely that you can do what you want without passing the response through a webhook gateway, we need to know your technical objective.

Highlighted
Level 7

Re: Webhook JSON response mapping - iterating values

I'm guessing you're trying to record the latest value so in response, you should look into using a handler that you code yourself

instead of sending the payload profileId={{lead.profileId}} directly to the external system, send the payload profileId={{lead.profileId}}&orderDate={{lead.orderDate}} to a handler which

1. forwards the request profileId={{lead.profileId}} to the external system and gets the full json response

2. parses the json response from the external system and handles the comparison logic for orderDate={{lead.orderDate}}

3. returns only the value for the latest orderDate {'orderDate':'2015-01-01'} to marketo

Highlighted
Level 7

Re: Webhook JSON response mapping - iterating values

alternatively, if you're only using the data in email comms and not for filtering or anything, you can then just write the whole response to a textarea field and manipulate the json using velocity