Replacing line items in an order not working

I’m in Sandbox, trying to remove a line item from an order. I’m following the instructions here to replace a field: Update Orders

In this example, I’m trying to remove the latte line item. However, the line items are not getting updated. The updated order line items still contain the latte.

Order I’m editing:

{
  "order": {
    "id": "3gEhn3Qfk5BOZIOwnzPLaWmBLTJZY",
    "location_id": "LNR8WX2PQJ3QP",
    "line_items": [
      {
        "uid": "qhEFkxeGhYfJq9YvemIiZC",
        "catalog_object_id": "HIP5ITYK7EKHLNB2JXJVSYLQ",
        "catalog_version": 1697214751535,
        "quantity": "1",
        "name": "Drip Coffee",
        "variation_name": "Large",
        "base_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "gross_sales_money": {
          "amount": 450,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_money": {
          "amount": 450,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "item_type": "ITEM",
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        }
      },
      {
        "uid": "jP9Fz1vueoL7ThAhHIZf1B",
        "catalog_object_id": "FG3EVAMYSIR4WEGQY5ZBO4JR",
        "catalog_version": 1697214751535,
        "quantity": "1",
        "name": "Latte",
        "variation_name": "Small, Hot",
        "base_price_money": {
          "amount": 480,
          "currency": "USD"
        },
        "modifiers": [
          {
            "uid": "9GXxio3VS1Xi6WW1WrzM4C",
            "base_price_money": {
              "amount": 100,
              "currency": "USD"
            },
            "total_price_money": {
              "amount": 100,
              "currency": "USD"
            },
            "name": "Vanilla",
            "catalog_object_id": "A5A6GSTWB4EPEQ4D3SPTM3EM",
            "catalog_version": 1697214751535,
            "quantity": "1"
          }
        ],
        "gross_sales_money": {
          "amount": 580,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_money": {
          "amount": 580,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 480,
          "currency": "USD"
        },
        "item_type": "ITEM",
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        }
      }
    ],
    "fulfillments": [
      {
        "uid": "DvGYlNcSicPBF9PUfK4LSD",
        "type": "PICKUP",
        "state": "PROPOSED",
        "pickup_details": {
          "pickup_at": "2023-10-31T16:58:10.390Z",
          "recipient": {
            "customer_id": "9ZV32FSJN9EQA6JT7WNRS5CRT4",
            "display_name": "(313) 599-5857",
            "phone_number": "+13135995857"
          }
        }
      }
    ],
    "created_at": "2023-10-31T16:42:36.412Z",
    "updated_at": "2023-10-31T16:43:12.185Z",
    "state": "DRAFT",
    "version": 2,
    "total_tax_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_discount_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_tip_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_money": {
      "amount": 1030,
      "currency": "USD"
    },
    "total_service_charge_money": {
      "amount": 0,
      "currency": "USD"
    },
    "net_amounts": {
      "total_money": {
        "amount": 1030,
        "currency": "USD"
      },
      "tax_money": {
        "amount": 0,
        "currency": "USD"
      },
      "discount_money": {
        "amount": 0,
        "currency": "USD"
      },
      "tip_money": {
        "amount": 0,
        "currency": "USD"
      },
      "service_charge_money": {
        "amount": 0,
        "currency": "USD"
      }
    },
    "source": {
      "name": "TextJoy"
    },
    "customer_id": "9ZV32FSJN9EQA6JT7WNRS5CRT4",
    "pricing_options": {
      "auto_apply_discounts": true,
      "auto_apply_taxes": true
    },
    "net_amount_due_money": {
      "amount": 1030,
      "currency": "USD"
    }
  }
}

Update request to remove line item:

{
  "order": {
    "version": 2,
    "location_id": "LNR8WX2PQJ3QP",
    "state": "DRAFT",
    "fulfillments": [
      {
        "pickup_details": {
          "pickup_at": "2023-10-31T16:58:51.809172"
        },
        "uid": "DvGYlNcSicPBF9PUfK4LSD"
      }
    ],
    "fields_to_clear": [
      "line_items"
    ],
    "line_items": [
      {
        "uid": "qhEFkxeGhYfJq9YvemIiZC",
        "name": "Drip Coffee",
        "quantity": "1",
        "item_type": "ITEM",
        "total_money": {
          "amount": 450,
          "currency": "USD"
        },
        "variation_name": "Large",
        "catalog_version": 1697214751535,
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "base_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "catalog_object_id": "HIP5ITYK7EKHLNB2JXJVSYLQ",
        "gross_sales_money": {
          "amount": 450,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 450,
          "currency": "USD"
        }
      }
    ]
  }
}

Response:

{
  "order": {
    "id": "3gEhn3Qfk5BOZIOwnzPLaWmBLTJZY",
    "location_id": "LNR8WX2PQJ3QP",
    "line_items": [
      {
        "uid": "qhEFkxeGhYfJq9YvemIiZC",
        "catalog_object_id": "HIP5ITYK7EKHLNB2JXJVSYLQ",
        "catalog_version": 1697214751535,
        "quantity": "1",
        "name": "Drip Coffee",
        "variation_name": "Large",
        "base_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "gross_sales_money": {
          "amount": 450,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_money": {
          "amount": 450,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "item_type": "ITEM",
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        }
      },
      {
        "uid": "jP9Fz1vueoL7ThAhHIZf1B",
        "catalog_object_id": "FG3EVAMYSIR4WEGQY5ZBO4JR",
        "catalog_version": 1697214751535,
        "quantity": "1",
        "name": "Latte",
        "variation_name": "Small, Hot",
        "base_price_money": {
          "amount": 480,
          "currency": "USD"
        },
        "modifiers": [
          {
            "uid": "9GXxio3VS1Xi6WW1WrzM4C",
            "base_price_money": {
              "amount": 100,
              "currency": "USD"
            },
            "total_price_money": {
              "amount": 100,
              "currency": "USD"
            },
            "name": "Vanilla",
            "catalog_object_id": "A5A6GSTWB4EPEQ4D3SPTM3EM",
            "catalog_version": 1697214751535,
            "quantity": "1"
          }
        ],
        "gross_sales_money": {
          "amount": 580,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_money": {
          "amount": 580,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 480,
          "currency": "USD"
        },
        "item_type": "ITEM",
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        }
      }
    ],
    "fulfillments": [
      {
        "uid": "DvGYlNcSicPBF9PUfK4LSD",
        "type": "PICKUP",
        "state": "PROPOSED",
        "pickup_details": {
          "pickup_at": "2023-10-31T16:58:51.809Z",
          "recipient": {
            "customer_id": "9ZV32FSJN9EQA6JT7WNRS5CRT4",
            "display_name": "(313) 599-5857",
            "phone_number": "+13135995857"
          }
        }
      }
    ],
    "created_at": "2023-10-31T16:42:36.412Z",
    "updated_at": "2023-10-31T16:43:52.548Z",
    "state": "DRAFT",
    "version": 3,
    "total_tax_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_discount_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_tip_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_money": {
      "amount": 1030,
      "currency": "USD"
    },
    "total_service_charge_money": {
      "amount": 0,
      "currency": "USD"
    },
    "net_amounts": {
      "total_money": {
        "amount": 1030,
        "currency": "USD"
      },
      "tax_money": {
        "amount": 0,
        "currency": "USD"
      },
      "discount_money": {
        "amount": 0,
        "currency": "USD"
      },
      "tip_money": {
        "amount": 0,
        "currency": "USD"
      },
      "service_charge_money": {
        "amount": 0,
        "currency": "USD"
      }
    },
    "source": {
      "name": "TextJoy"
    },
    "customer_id": "9ZV32FSJN9EQA6JT7WNRS5CRT4",
    "pricing_options": {
      "auto_apply_discounts": true,
      "auto_apply_taxes": true
    },
    "net_amount_due_money": {
      "amount": 1030,
      "currency": "USD"
    }
  }
}

When updating the order you don’t need to include the totals and you’ll only provide the uid and catalog_object_id. It will look like:

{
  "order": {
    "version": 1,
    "location_id": "{{location_id}}",
    "state": "DRAFT",
    "fulfillments": [
      {
        "pickup_details": {
          "pickup_at": "2023-10-31T16:58:51.809172"
        },
        "uid": "T2ZuIqpmV6LErTC6cdt9ZB"
      }
    ],
    "fields_to_clear": [
      "line_items"
    ],
    "line_items": [
            {
                "uid": "iLAt0hM2EB54bvt9BShZND",
                "catalog_object_id": "M4ZCRV2XZ6E76FC5XDDJZQTK"
            }
    ]
  }
}

:slightly_smiling_face:

Thanks Bryan!

So to remove a line item from an array of line items, you have to provide the uid and catalog object id of the line item you want to keep?

And you provided line_items in your fields_to_clear in your example above. Is that necessary?

The example will remove the line item from the order. Adding an item will be different. In the above request fields_to_clear are line_items. Of the line_items its clearing the catalog object I’ve identified with uid and catalog_object_id. :slightly_smiling_face:

I’m trying to update a field, not delete it.

In my example, I’m trying to update the Order line_items array.

Are you saying that to update the field, I first need to clear it, then add the new values?

No, you don’t need to clear it before updating it. What field are you updating? :slightly_smiling_face:

I’m updating line_items

Great! What exactly are you updating? Price, quantity, etc …? :slightly_smiling_face:

I’m updating the line_items array.

So here’s the before:

"line_items": [
      {
        "uid": "qhEFkxeGhYfJq9YvemIiZC",
        "catalog_object_id": "HIP5ITYK7EKHLNB2JXJVSYLQ",
        "catalog_version": 1697214751535,
        "quantity": "1",
        "name": "Drip Coffee",
        "variation_name": "Large",
        "base_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "gross_sales_money": {
          "amount": 450,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_money": {
          "amount": 450,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "item_type": "ITEM",
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        }
      },
      {
        "uid": "jP9Fz1vueoL7ThAhHIZf1B",
        "catalog_object_id": "FG3EVAMYSIR4WEGQY5ZBO4JR",
        "catalog_version": 1697214751535,
        "quantity": "1",
        "name": "Latte",
        "variation_name": "Small, Hot",
        "base_price_money": {
          "amount": 480,
          "currency": "USD"
        },
        "modifiers": [
          {
            "uid": "9GXxio3VS1Xi6WW1WrzM4C",
            "base_price_money": {
              "amount": 100,
              "currency": "USD"
            },
            "total_price_money": {
              "amount": 100,
              "currency": "USD"
            },
            "name": "Vanilla",
            "catalog_object_id": "A5A6GSTWB4EPEQ4D3SPTM3EM",
            "catalog_version": 1697214751535,
            "quantity": "1"
          }
        ],
        "gross_sales_money": {
          "amount": 580,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_money": {
          "amount": 580,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 480,
          "currency": "USD"
        },
        "item_type": "ITEM",
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        }
      }
    ]

And here it is with the second line item (Latte) removed:

"line_items": [
      {
        "uid": "qhEFkxeGhYfJq9YvemIiZC",
        "name": "Drip Coffee",
        "quantity": "1",
        "item_type": "ITEM",
        "total_money": {
          "amount": 450,
          "currency": "USD"
        },
        "variation_name": "Large",
        "catalog_version": 1697214751535,
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "base_price_money": {
          "amount": 450,
          "currency": "USD"
        },
        "catalog_object_id": "HIP5ITYK7EKHLNB2JXJVSYLQ",
        "gross_sales_money": {
          "amount": 450,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_service_charge_money": {
          "amount": 0,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 450,
          "currency": "USD"
        }
      }
    ]

Thanks Bryan!