# Remove Order line Item using update Api

**URL:** <https://developer.squareup.com/forums/t/remove-order-line-item-using-update-api/18166>\
**Category:** Questions\
**Tags:** orders-api\
**Created:** [August 7, 2024, 6:12am UTC](https://developer.squareup.com/forums/t/remove-order-line-item-using-update-api/18166 "2024-08-07T06:12:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![selvaganapathi.A](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@selvaganapathi.A](https://developer.squareup.com/forums/u/selvaganapathi.A)\
**Post date:** [August 7, 2024, 6:12am UTC](https://developer.squareup.com/forums/t/remove-order-line-item-using-update-api/18166/1 "2024-08-07T06:12:40Z")

</div>

My Request  
{  
“order”: {  
“state”: “OPEN”,  
“source”: {  
“name”: “CaterZen”  
},  
“reference\_id”: “1678034”,  
“location\_id”: “LNMMT9D8WJNMC”,  
“customer\_id”: “YMWPBJDXGYV3T2DFCWHS8DA76G”,  
“line\_items”: [  
{  
“quantity”: “10”,  
“name”: “1/2 1/2 TEA”,  
“base\_price\_money”: {  
“amount”: 279,  
“currency”: “USD”  
},  
“modifiers”: [  
{  
“uid”: “DE3QYJCDO4SBCZLQW5UOJWZY”,  
“name”: “DIET”,  
“base\_price\_money”: {  
“amount”: 2000,  
“currency”: “USD”  
},  
“catalog\_object\_id”: “DE3QYJCDO4SBCZLQW5UOJWZY”  
}  
],  
“variation”: {  
“uid”: “Z6FBA6DCAJAMNFHSEVBHAUIT”,  
“name”: “Small”  
},  
“note”: “”,  
“catalog\_object\_id”: “Z6FBA6DCAJAMNFHSEVBHAUIT”,  
“uid”: “AFOYDFJDJYHRUEF27BTD4NK7”,  
“variation\_name”: “Small”  
}  
],  
“discounts”: [  
{  
“name”: “10% discount”,  
“percentage”: “10”,  
“type”: “FIXED\_PERCENTAGE”,  
“scope”: “ORDER”,  
“uid”: “145670”  
}  
],  
“taxes”: ,  
“metadata”: {  
“note”: “CaterZen Order”  
},  
“version”: 1,  
“fulfillments”: [  
{  
“type”: “PICKUP”,  
“pickup\_details”: {  
“recipient”: {  
“customer\_id”: “YMWPBJDXGYV3T2DFCWHS8DA76G”  
},  
“state”: “PROPOSED”,  
“pickup\_at”: “2024-08-07T22:00:00-07:00”  
},  
“uid”: “S0GNh9jh2pQ0PV0a62bZVD”  
}  
]  
},  
“fields\_to\_clear”: [  
“line\_items”  
]  
}

Response

{  
“status”: 400,  
“reason”: “Bad Request”,  
“error”: {  
“errors”: [  
{  
“code”: “INVALID\_VALUE”,  
“detail”: “Read-only field is calculated and cannot be set by a client.”,  
“field”: “order.line\_items[AFOYDFJDJYHRUEF27BTD4NK7].gross\_sales\_money”,  
“category”: “INVALID\_REQUEST\_ERROR”  
}  
]  
}  
}

I add 2 line line item and place order.  
then i remove last line item i got this error.Please anyone solve this issue??

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [August 7, 2024, 6:13am UTC](https://developer.squareup.com/forums/t/remove-order-line-item-using-update-api/18166/2 "2024-08-07T06:13:27Z")

</div>

👋 I’m Square Dev AI, here to help answer your question!  
Based on the information you’ve provided, the following documentation will help answer your question:

> **[Create Orders](https://developer.squareup.com/docs/orders-api/create-orders)**
>
> Learn how to create an order, add line items, and track fulfillment.

> **[Orders API: How It Works](https://developer.squareup.com/docs/orders-api/how-it-works)**
>
> Learn how the Orders API processes and returns information.

> **Additional Documentation**
>
> [Update Orders](https://developer.squareup.com/docs/orders-api/manage-orders/update-orders)  
> [Order Fulfillments](https://developer.squareup.com/docs/orders-api/fulfillments)  
> [Clear API Object Fields](https://developer.squareup.com/docs/build-basics/clearing-fields)

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.  
Otherwise one of our Developer Advocates will provide additional assistance shortly.

---

<div class="post-metadata">

**Author:** ![selvaganapathi.A](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@selvaganapathi.A](https://developer.squareup.com/forums/u/selvaganapathi.A)\
**Post date:** [August 7, 2024, 6:14am UTC](https://developer.squareup.com/forums/t/remove-order-line-item-using-update-api/18166/3 "2024-08-07T06:14:58Z")

</div>

I am already check this this document .but no improvements

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [August 7, 2024, 4:03pm UTC](https://developer.squareup.com/forums/t/remove-order-line-item-using-update-api/18166/4 "2024-08-07T16:03:42Z")

</div>

The error message indicates that you’re trying to modify a read-only field, specifically the `gross_sales_money` field under `order.line_items`. This field is calculated by Square and cannot be directly modified by a client.

When you’re trying to update an order, you should only include the fields that you want to change in the request body. If you want to remove a line item, you should not include the `gross_sales_money` field in your request.

If you want to remove a line item from an order, you should use the `UpdateOrder` endpoint and specify the line item to be removed in the `fields_to_clear` array. The value should be `line_items.<uid>`, where `<uid>` is the unique identifier of the line item you want to remove.

In your case, if you want to remove the last line item, your `fields_to_clear` array should look like this:

```auto
"fields_to_clear": [
    "line_items.AFOYDFJDJYHRUEF27BTD4NK7"
]

```

This tells Square to remove the line item with the uid `AFOYDFJDJYHRUEF27BTD4NK7` from the order.

_This answer was reviewed by @Bryan-Square._

---

<div class="post-metadata">

**Author:** ![helle253](https://avatars.discourse-cdn.com/v4/letter/h/ecccb3/32.png) [@helle253](https://developer.squareup.com/forums/u/helle253)\
**Post date:** [February 12, 2025, 9:51pm UTC](https://developer.squareup.com/forums/t/remove-order-line-item-using-update-api/18166/5 "2025-02-12T21:51:37Z")

</div>

```json
"fields_to_clear": [
    "line_items.AFOYDFJDJYHRUEF27BTD4NK7"
]

```

I believe this is incorrect, as array access is needed. This is the correct format:

```json
"fields_to_clear": [
    "line_items[AFOYDFJDJYHRUEF27BTD4NK7]"
]

```

However, when attempting to remove a line item on an order with **voided payments** this still causes issues. I am experiencing a similar issue with my request:

I am sending this sparse json object to the `update_order` endpoint, and expect line item uid\_1 to be removed:

```json
{
  "order": {
    "line_items": [
      {
        "quantity": "1",
        "uid": "uid_1",
        "note": "",
        "catalog_object_id": "id_1",
        "modifiers": [],
        "applied_taxes": [
          {
            "uid": "applied_tax_1",
            "tax_uid": "tax_1"
          }
        ],
        "applied_discounts": [
          {
            "uid": "applied_discount_1",
            "discount_uid": "discount_1"
          }
        ]
      },
      {
        "quantity": "1",
        "uid": "uid_2",
        "note": "",
        "catalog_object_id": "id_2",
        "modifiers": [],
        "applied_taxes": [
          {
            "uid": "applied_tax_2",
            "tax_uid": "tax_2"
          }
        ],
        "applied_discounts": [
          {
            "uid": "applied_discount_2",
            "discount_uid": "discount_2"
          }
        ]
      }
    ],
    "taxes": [
      {
        "uid": "tax_1",
        "name": "Tax 1",
        "type": "ADDITIVE",
        "percentage": "5",
        "scope": "LINE_ITEM"
      },
      {
        "uid": "tax_2",
        "name": "Tax 2",
        "type": "ADDITIVE",
        "percentage": "4",
        "scope": "LINE_ITEM"
      }
    ],
    "discounts": [
      {
        "uid": "discount_1",
        "scope": "LINE_ITEM",
        "type": "FIXED_AMOUNT",
        "name": "Discount",
        "amount_money": {
          "amount": 50,
          "currency": "USD"
        }
      },
      {
        "uid": "discount_2",
        "scope": "LINE_ITEM",
        "type": "FIXED_AMOUNT",
        "name": "Discount",
        "amount_money": {
          "amount": 25,
          "currency": "USD"
        }
      }
    ],
    "fulfillments": [
      {
        "type": "PICKUP",
        "uid": "order_uid",
        "pickup_details": {
          "recipient": {
            "customer_id": "customer_1"
          },
          "is_square_pickup_order": true,
          "pickup_at": "2025-01-01T00:00:00+00:00",
          "prep_time_duration": "PT5M"
        }
      }
    ],
    "version": 17
  },
  "fields_to_clear": [
    "line_items[uid_1]"
  ],
  "idempotency_key": "idempotency_key"
}

```

However, I get this error response:

```json
{
  "code": "INVALID_VALUE",
  "detail": "Read-only field is calculated and cannot be set by a client.",
  "field": "order.line_items[uid_1].gross_sales_money",
  "category": "INVALID_REQUEST_ERROR"
}

```

I am not touching this calculated field, I am removing the line item it is attached to. Given that the previous payments have been voided, I would expect this to work without issue, but that is not the case.

Please advise. Currently my workaround will be to recreate this order entirely, because I am functionally unable to update it at all once a payment is attempted (and failed)
