Hi - we are trying to split out items with this result but it’s not working. Any thoughts?
Did you try the “Item Lists” node?
You can find the documentation here.
Yes we did. But it couldn’t find the field called “contact”. There must be something we are missing…
Hi @The_Leading_Practice , contact itself wouldn’t be a field that could be split out from the looks of it (since it’s not a list/an array). Do you just want to see all the fields inside contact at the top level? If so, you could run something like return item.contact;
in a Function Item node.
Example Workflow
I have this saved code snippet with a brief description to use in situations like this. You need to put it in a function node and change “results” to “contact”.
Sometimes (e.g. with external APIs returning data in a different format), you will encounter nested items. This usually means the data we are interested in is its own object nested within the JSON response from the API.
Where “results” is the object/array of interest, we would modify our function above as so:
return items[0].json.results.map(item => ( { json : item } ));
Thank you for the help @automatron
Here’s my code:
return items[0].json.contact.map(item => ( { json : item } ));
Here’s the error I’m now receiving:
ERROR: Cannot read property ‘map’ of undefined
I tried these… they didn’t work.
return item.contact;
return item.json.contact;
return items[0].json.contact;
Could you share an example workflow returning the problematic data structure?
Here’s the raw output of HTTP Request node.
Items: 1
[
{
"contact": {
"id": "UVsQqOnTIdnKNnhKscIO",
"firstName": "xxxx",
"lastNameLowerCase": "xxxx",
"country": "US",
"fullNameLowerCase": "xxxx xxxx",
"locationId": "mTx5jaBRMAEHPlMfQbiX",
"tags": [
"ct appt",
"existing patient",
"zap"
],
"lastName": "xxxx",
"type": "lead",
"emailLowerCase": "xxxxx",
"dateAdded": "2021-10-29T15:03:39.000Z",
"phone": "+xxxxx",
"email": "xxxx",
"firstNameLowerCase": "xxxx",
"source": "api v1",
"customField": [
]
}
}
]
Could you share the workflow where the Function Item example I have provided isn’t working? Because when trying this on my end it is working fine using your example data (though I am still not 100% sure this is what you would like to see in the end):
Here’s my example workflow using your data:
Workflow
So it would be tremendously helpful if you could share your workflow’s JSON representation to see the problem first hand.
So sorry guys! After further examination, I was using the Function node instead of Function Item.
Your solution works great! Thank you for your help!
Awesome, I am glad to hear that, thanks so much for confirming! Have a nice weekend and go reach out if anything else comes up