Webhook JSON response mapping - iterating values

Asha_Kamble1
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

7 REPLIES 7
SanfordWhiteman
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.

Jay_Jiang
Level 10

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

Jay_Jiang
Level 10

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

Oz_Platero
Level 6

Re: Webhook JSON response mapping - iterating values

@Jay_Jiang ,

How would you go about capturing the whole JSON response?

thanks

SanfordWhiteman
Level 10 - Community Moderator

Re: Webhook JSON response mapping - iterating values

This assumes you're either controlling the endpoint completely, or controlling an in-between gateway that can change/augment the response payload on the fly.

 

But the idea is you stringify the original JSON and put that in another property, e.g.

 

{"fullResponse":"{\"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\"}]}"}

 

Oz_Platero
Level 6

Re: Webhook JSON response mapping - iterating values

@SanfordWhiteman ,

I am not able to control the endpoint or an in-between gateway at the moment.
Thanks for the info for future use!

Jay_Jiang
Level 10

Re: Webhook JSON response mapping - iterating values

Sandford's got you covered.

 

Obvious tip, but make sure you've selected Response Type: JSON in your webhook settings