SOLVED

Re: Webhook Response Mapping when the results are random

Go to solution
michaelstancil
Level 3

Webhook Response Mapping when the results are random

Hi there,

 

I have a webhook calling an API returns a list of items, the only issue is the results are not formatted the same each time, so the value of item[1].itemName may be "Blue Cars" in one call, and "Red Cars" in another, and I'm trying to get the count. All of the items I need are provided in the response, I'm just not sure how (and if) I can add the item name (with spaces) to the response attribute to grab the value.

 

I have scrubbed the response, but note that I do receive values with a space in-between them (Blue space car) as well as slashes (Green slash Blue car)

 

{"car_count":123456,"item_count":117733,"item_types":[{"item_type":"Blue Car","item_type_count":1115,"item_type_ratio":12},{"item_type":"Red Car","item_type_count":1225,"item_type_ratio":14},{"item_type":"Green/Blue Car","item_type_count":1345,"item_type_ratio":6}],"item_types_ratio":22}
Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Webhook Response Mapping when the results are random

You can’t do this with the simple dot-and-bracket notation of a Response Mapping, because there’s no way to find a property value by another property value. You’d need something like JSONPath for that, which isn’t supported.

 

So you‘d need to call your API via another intermediate webhook (i.e. “webhook gateway”) that transforms the data on-the-fly for Marketo consumption.

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Webhook Response Mapping when the results are random

You can’t do this with the simple dot-and-bracket notation of a Response Mapping, because there’s no way to find a property value by another property value. You’d need something like JSONPath for that, which isn’t supported.

 

So you‘d need to call your API via another intermediate webhook (i.e. “webhook gateway”) that transforms the data on-the-fly for Marketo consumption.

michaelstancil
Level 3

Re: Webhook Response Mapping when the results are random

@SanfordWhiteman I was hoping you would response, big fan! As far as a webhook gateway, do you have any recommendations on services that do that?

 

As far as this request, luckily the API service was able to update their service over the weekend so that I could do key value pairs,!

SanfordWhiteman
Level 10 - Community Moderator

Re: Webhook Response Mapping when the results are random


As far as a webhook gateway, do you have any recommendations on services that do that?

Sure, you could’ve done that with AWS API Gateway since the transform is pretty simple.

 

AWS APIGW supports JSONPath so for example you can use the expression

$.item_types[?(@.item_type == "Blue Car")].item_type_count

which will return the item_type_count for the object with item_type "Blue Car".

 

Then you can use Velocity (!) to do other fun stuff with the results.

SanfordWhiteman
Level 10 - Community Moderator

Re: Webhook Response Mapping when the results are random

michaelstancil
Level 3

Re: Webhook Response Mapping when the results are random

Thanks!