To handle Shopify order data properties and variants, you can use Code by Zapier

  • 29 November 2023
  • 0 replies
  • 69 views

I referred to the following article but could not solve the problem.

 

I tried Webhoo, App Extension, and etc. Finally I tried “Code” like below.

const order_id = inputData['orderid'];
const res = await fetch(
'https://YOUR-STORE-SUBDOMAIN.myshopify.com/admin/api/2023-10/orders/' + order_id + '.json?fields=line_items',
{
headers: { 'X-Shopify-Access-Token' : 'HERE IS YOUR API TOKEN' }
}
);

const json = await res.json();

let line_items = [];
for( const item of json.order.line_items ) {
let prop = '';
for( const p of item.properties ) {
prop += p.name + ': ' + p.value + "\n";
}

line_items.push({
product_id: item.product_id,
name: item.name,
prop: prop,
variant: item.variant_title
});
}

output = { line_items: line_items };

 

This code takes a Shopify order ID as input data, retrieves the data via the API, parses the line_items and converts it to the format it wants. It then sets it as output data.

The line_items key is used to handle the data as an array in Zapier. You can then use it in loops and so on.

Shopify API tokens can be obtained from the Shopify administration screen, in the settings and in the app development.

I'd be happy to help!

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.