conscious-sapphire
conscious-sapphire2y ago

Trouble saving meta data from API GET Call

I'm having a problem with saving meta data value from my WC REST API entry in Voiceflow API Block using Capture Response. Headers are correct (Authorization and Content-Type) and I get successful API calls and even pull/save data into variables (e.g. Order Number, Order Status, Shipping Address). However, whilst trying to save the backordered value using
line_items[0].meta_data[?(@.key=='Backordered')].value
line_items[0].meta_data[?(@.key=='Backordered')].value
it simply results in an empty (default) variable. I'm incredibly new to all of this (Voiceflow and APIs) but can't seem to solve the issue even with GPT4 or the documentation. I'm not sure how i would go about solving this. https://www.WEBSITE/wp-json/wc/v3/orders/{order_number}
"id": XXXXX1,
"status": "pending",
"billing": {...},
"shipping": {...},
"order_number": "XXXX2",
"line_items": [
{
"id": 58290,
"name": "ITEM NAME",
"product_id": XXXXX3,
"variation_id": XXXXX4,
"quantity": 1,
"tax_class": "",
"subtotal": "1220.95",
"subtotal_tax": "0.00",
"total": "1220.95",
"total_tax": "0.00",
"taxes": [],
"meta_data": [
{
"id": 672070,
"key": "pa_colour",
"value": "white",
"display_key": "Colour",
"display_value": "White"
},
{
"id": 672072,
"key": "Backordered",
"value": "1",
"display_key": "Backordered",
"display_value": "1"
}
],
"id": XXXXX1,
"status": "pending",
"billing": {...},
"shipping": {...},
"order_number": "XXXX2",
"line_items": [
{
"id": 58290,
"name": "ITEM NAME",
"product_id": XXXXX3,
"variation_id": XXXXX4,
"quantity": 1,
"tax_class": "",
"subtotal": "1220.95",
"subtotal_tax": "0.00",
"total": "1220.95",
"total_tax": "0.00",
"taxes": [],
"meta_data": [
{
"id": 672070,
"key": "pa_colour",
"value": "white",
"display_key": "Colour",
"display_value": "White"
},
{
"id": 672072,
"key": "Backordered",
"value": "1",
"display_key": "Backordered",
"display_value": "1"
}
],
No description
No description
1 Reply
W. Williams (SFT)
I posted this in another thred:
function findBackordered(items) {
// Loop through each item in the array
for (const item of items) {
// Check each meta_data entry
for (const metaData of item.line_items[0].meta_data) {
// Convert the key to lowercase for case insensitive comparison
if (metaData.key.toLowerCase() === 'backordered') {
return metaData.value; // Return the value when the key matches 'backordered'
}
}
}
return null; // Return null if 'backordered' key is not found
}

// Usage
const backorderedValue = findBackordered(vfApiVarName);
function findBackordered(items) {
// Loop through each item in the array
for (const item of items) {
// Check each meta_data entry
for (const metaData of item.line_items[0].meta_data) {
// Convert the key to lowercase for case insensitive comparison
if (metaData.key.toLowerCase() === 'backordered') {
return metaData.value; // Return the value when the key matches 'backordered'
}
}
}
return null; // Return null if 'backordered' key is not found
}

// Usage
const backorderedValue = findBackordered(vfApiVarName);
Put this in a Javascript step.

Did you find this page helpful?