Duplicated LineItems when updating Draft Order via REST API

ndzyadovich
Tourist
4 0 7

Hello everyone!

 

I faced a problem with the PUT DraftOrder endpoint.

 

When I send multiple request with the same content for a draft order that already have line items added to it, I end up with having these items duplicated in a response.

 

Request example:

 

PUT /admin/api/2022-01/draft_orders/100.json

 

{
  "draft_order" : {
    "id" : 100,
    "line_items" : [ {
      "id": 1000000,
      "variant_id": 1000001,
      "product_id": 1000002,
      "title": "product title",
      "variant_title": "XS / Black",
      "vendor": "cool shop",
      "quantity": 1,
      "requires_shipping": true,
      "taxable": true,
      "gift_card": false,
      "fulfillment_service": "manual",
      "grams": 0,
      "applied_discount": null,
      "price": "1495.00"
    } ],
    "total_price": "1618.34",
    "subtotal_price": "1495.00",
    "total_tax": "123.34",
    "taxes_included" : false,
    "status" : "open",
    "currency" : "USD",
    "applied_discount" : null
  }
}

 

 

Response example:

 

 

{
  "draft_order": {
    "id": 100,
    "note": null,
    "email": null,
    "taxes_included": false,
    "currency": "USD",
    "invoice_sent_at": null,
    "created_at": "2022-03-24T12:43:17-05:00",
    "updated_at": "2022-03-24T12:43:17-05:00",
    "tax_exempt": false,
    "completed_at": null,
    "name": "#D265167",
    "status": "open",
    "line_items": [
      {
        "id": 1000000,
        "variant_id": 1000001,
        "product_id": 1000002,
        "title": "product title",
        "variant_title": "XS / Black",
        "sku": "",
        "vendor": "cool shop",
        "quantity": 1,
        "requires_shipping": true,
        "taxable": true,
        "gift_card": false,
        "fulfillment_service": "manual",
        "grams": 0,
        "tax_lines": [
          {
            "rate": 0.0625,
            "title": "Texas State Tax",
            "price": "93.44"
          },
          {
            "rate": 0.02,
            "title": "Dallas City Tax",
            "price": "29.90"
          }
        ],
        "applied_discount": null,
        "name": "product title - XS / Black",
        "properties": [],
        "custom": false,
        "price": "1495.00",
        "admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/1000000"
      },
      {
        "id": 1000003,
        "variant_id": 1000001,
        "product_id": 1000002,
        "title": "product title",
        "variant_title": "XS / Black",
        "sku": "",
        "vendor": "cool shop",
        "quantity": 1,
        "requires_shipping": true,
        "taxable": true,
        "gift_card": false,
        "fulfillment_service": "manual",
        "grams": 0,
        "tax_lines": [
          {
            "rate": 0.0625,
            "title": "Texas State Tax",
            "price": "93.44"
          },
          {
            "rate": 0.02,
            "title": "Dallas City Tax",
            "price": "29.90"
          }
        ],
        "applied_discount": null,
        "name": "product title - XS / Black",
        "properties": [],
        "custom": false,
        "price": "1495.00",
        "admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/1000000"
      },
      {
        "id": 1000004,
        "variant_id": 1000001,
        "product_id": 1000002,
        "title": "product title",
        "variant_title": "XS / Black",
        "sku": "",
        "vendor": "cool shop",
        "quantity": 1,
        "requires_shipping": true,
        "taxable": true,
        "gift_card": false,
        "fulfillment_service": "manual",
        "grams": 0,
        "tax_lines": [
          {
            "rate": 0.0625,
            "title": "Texas State Tax",
            "price": "93.44"
          },
          {
            "rate": 0.02,
            "title": "Dallas City Tax",
            "price": "29.90"
          }
        ],
        "applied_discount": null,
        "name": "product title - XS / Black",
        "properties": [],
        "custom": false,
        "price": "1495.00",
        "admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/1000000"
      },
      {
        "id": 1000005,
        "variant_id": 1000001,
        "product_id": 1000002,
        "title": "product title",
        "variant_title": "XS / Black",
        "sku": "",
        "vendor": "cool shop",
        "quantity": 1,
        "requires_shipping": true,
        "taxable": true,
        "gift_card": false,
        "fulfillment_service": "manual",
        "grams": 0,
        "tax_lines": [
          {
            "rate": 0.0625,
            "title": "Texas State Tax",
            "price": "93.44"
          },
          {
            "rate": 0.02,
            "title": "Dallas City Tax",
            "price": "29.90"
          }
        ],
        "applied_discount": null,
        "name": "product title - XS / Black",
        "properties": [],
        "custom": false,
        "price": "1495.00",
        "admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/1000003"
      }
    ],
    "shipping_address": null,
    "billing_address": null,
    "invoice_url": "https://my-store.myshopify.com/000000000/invoices/0000000",
    "applied_discount": null,
    "order_id": null,
    "shipping_line": null,
    "tax_lines": [
      {
        "rate": 0.0625,
        "title": "Texas State Tax",
        "price": "93.44"
      },
      {
        "rate": 0.02,
        "title": "Dallas City Tax",
        "price": "29.90"
      },
      {
        "rate": 0.0625,
        "title": "Texas State Tax",
        "price": "93.44"
      },
      {
        "rate": 0.02,
        "title": "Dallas City Tax",
        "price": "29.90"
      }
    ],
    "tags": "",
    "note_attributes": [],
    "total_price": "1618.34",
    "subtotal_price": "1495.00",
    "total_tax": "123.34",
    "payment_terms": null,
    "admin_graphql_api_id": "gid://shopify/DraftOrder/100",
    "customer": null
  }
}

 

 

And after some time i get the total updated according to the generated items list. 

The problem appears only when sending multiple requests simultaneously.

Reply 1 (1)

ZVNDEV
Shopify Partner
6 0 2

I'm having the same issue. I'm updating a store's line item properties on a draft order based off of a Draft Order Updated Webhook from Shopify - always passing back the same line items.  Shopify is duplicating all line items in the draft order though.  Seems like a bug.  Any fix yet?

- Kirby
zvndev.com