API Post to Shopify Ignores Array

Tourist
4 0 1
I am using Zapier to create a custom API call to Shopify. My code works expect for the fact that it doesn't create multiple line items, so instead it makes a single line item like this:

enter image description here

"LINE ITEM EDIT" and "new" are the two test line items. And the code that makes it work:

 

 
const options = {  url: 'https://appaccount.myshopify.com/admin/draft_orders.json',  method: 'POST',  headers: {
    'Content-Type': 'application/json',
    'Accept': '*/*'

  },  params: {
},
  body: {
    
  "draft_order": {
    "tags": "ESTIMATE " +  bundle.inputData.customer,
    "email": bundle.inputData.email,
    "shipping":  bundle.inputData.shippingcost,
    "line_items":[
  {
        "title": bundle.inputData.desc,
        "quantity":  bundle.inputData.qty,
        "price":  bundle.inputData.amount
      
  } ]
    ,
    "note_attributes": [
      {
        "REG":  bundle.inputData.reg,
        "CALL #":  bundle.inputData.callnumber,
        "ESTIMATE ID":  bundle.inputData.estimateid,
        "SHIP VIA":  bundle.inputData.shipvia,
        "TRACKING #":  bundle.inputData.trackingnumber,
        "WORK ORDER #":  bundle.inputData.workordernumber
       
        
        
      }
     ],
     "shipping_line": {
      "price": bundle.inputData.shippingcost,
      "title": "TOTAL"
     },
    "customer":{
      "email": bundle.inputData.email
      
      
    } 
  }

    
}
}
return z.request(options)
  .then((response) => {    response.throwForStatus();
    const results = z.JSON.parse(response.content);

    // You can do any parsing you need for results here before returning them

    return results;
  });

 

So I should have 2 line items, not one. If you don't know Zapier don't worry about it. The bundle.inputData.somethinghereare just variables that store the data. So the example data would be simplified as this: bundle.inputData.desc = ["LINE ITEM EDIT"],["new"]. So I believe I am passing an array but Shopify isn't seeing it that way.

 

To summarize, Shopify is not accepting my array as multiple line items. Instead it takes the array and posts it as a single line item.

0 Likes
Shopify Staff
Shopify Staff
1469 67 219

Using a standard API call, I can create a draft order with one or more line items in an array without issue. I can't speak to how Zapier is supposed to work, have you tried contacting them?

 

Also, if I'm taking your code literally, there's only one line item in your array. Is this some quirk of Zapier that I'm not seeing?

0 Likes