MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
954 stars 280 forks source link

Unable to add properties to line_items #630

Closed Hpanday closed 1 year ago

Hpanday commented 1 year ago

Hey all, I am trying to create orders in my shopify store using order.create but I am unable to add properties to a line_item. I want the properties to show as below in the store. image

My code is as follows

const lineItems = line_item_rows.map((item) => {
      return {
        name: item["Line: Name"],
        price: item["Line: Price"],
        product_id: item["Line: Product ID"],
        properties: PROPERTIES,
        quantity: item["Line: Quantity"],
        requires_shipping: item["Line: Requires Shipping"],
        sku: item["Line: SKU"],
        taxable: item["Line: Taxable"],
        title: item["Line: Title"],
        variant_id: item["Line: Variant ID"],
        variant_title: item["Line: Variant Title"],
        vendor: item["Line: Vendor"],
        gift_card: item["Line: Gift Card"],
        total_discount: item["Line: Discount"],
      };
    });

    try {
      const create_order = await shopify.order.create({
        contact_email: line_item_rows[0].Email,
        name: line_item_rows[0].Name,
        currency: line_item_rows[0].Currency,
        customer: customerDetails,
        financial_status: line_item_rows[0]["Payment: Status"].toLowerCase(),
        phone: null, //line_item_rows[0].Phone,
        billing_address: billingDetails,
        shipping_address: shippingDetails,
        line_items: lineItems,
        tags: line_item_rows[0].Tags,
      });
    } catch (e) {
      console.log(e.response.body);
    }

but when I try to execute this, in the store nothing get's added in line_item's property field but everything else gets added perfectly (I have also checked the order using the API call to and there also line item properties show up as empty array). Am I doing something wrong? Is there a way to add line_item properties?

P.S. - Previously I was adding orders using a shopify app called MATRIXIFY throught the line item properties are added perfectly.

Hpanday commented 1 year ago

using this format for properties allowed me to add them to line_items

const payload = {
  order: {
    line_items: [
      {
        variant_id: 123456789,
        quantity: 1,
        properties: [
          {
            name: "Custom Property 1",
            value: "Value 1"
          },
          {
            name: "Custom Property 2",
            value: "Value 2"
          }
          // Add more properties as needed
        ]
      }
      // Add more line items if needed
    ]
  }
};