Hi there, I’m trying to select some child-values from some json data I receive from a woocommerce webhook. Specifically, I’m looking to extract the “sku” values (and only that) from the products purchased on the order received. So, the json data from woocommerce looks like this (simplified):
[
{
"body": {
"id": 9182,
"parent_id": 0,
"number":9615,
"line_items": [
{
"id":1606,
"name":"product-name-1",
"quantity":1,
"sku":"NN99-1234",
"price":20
},
{
"id":1608,
"name":"product-name-2,
"quantity":1,
"sku":"RR88-7890",
"price":15
}
]
},
"header": {
"host":"n8n.thinkmojo.com",
"x-real-ip":"35.209.249.90"
},
"query": {
}
}
]
The problem is that I can’t seem to find a way to select just the “sku” values. I can only find a way to get either the whole “line_items” values (that don’t need), or the sku of one specific product only. But I want the sku of each and everyone of the products from that order.
Here’s what I tried that in a function node (webhook->function node).
{{$node[“Webhook1”].json[“body”][“line_items”]}}
But this gives me a too much data:
[Array: [{"id":1614,"name":"test-seb-api-2","product_id":9604,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"0.00","subtotal_tax":"0.00","total":"0.00","total_tax":"0.00","taxes":[],"meta_data":[{"id":14453,"key":"_reduced_stock","value":"1"}],"sku":"NN99-1234","price":0},{"id":1615,"name":"test-seb-api","product_id":9592,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"0.00","subtotal_tax":"0.00","total":"0.00","total_tax":"0.00","taxes":[],"meta_data":[{"id":14454,"key":"_reduced_stock","value":"1"}],"sku":"AQ67-2376-2","price":0}]]
I also tried this:
{{$node[“Webhook1”].json[“body”][“line_items”][0][“sku”]}}
But this gives me the sku of only one product.
NN99-1234
If we take this example, my goal is to end up with these values:
NN99-1234
AQ67-2376-2
I’m sure there’s an easy way to do this, but an’t seem to find it. Any help would be amazing. Thanks a lot!