# Orders API: Cancel an order via the API

**URL:** <https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971>\
**Category:** Questions\
**Tags:** orders-api, sandbox\
**Created:** [December 6, 2024, 9:27am UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971 "2024-12-06T09:27:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lakshmi](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@lakshmi](https://developer.squareup.com/forums/u/lakshmi)\
**Post date:** [December 6, 2024, 9:27am UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/1 "2024-12-06T09:27:13Z")

</div>

Hello,  
I am trying to understand how to cancel an order.  
These are the steps I do:  
1- Create an order with a pickup fulfilment. (set auto\_complete\_duration)  
2- Create a payment for the order  
3- Call update order- set the state of the fulfillment to RESERVED.  
4- If nothing else is done- the order gets autocompleted - state = COMPLETE.

Say between 3 and 4, I want to now cancel the order.  
If i call update order with order STATE = CANCELLED, i get an error  
“code”: “BAD\_REQUEST”,  
“detail”: “Orders cannot be canceled after payments have been processed.”,  
“field”: “order.state”,

If i issue a refund on the payment created at 2, the refund gets created successfully.  
But i still can’t cancel the order, i get the same error message.  
If i cancel the order via the square sandbox UI, i can do it- successfully.

My question is - what is the way to cancel an order - with or without refunds, via the API.

Thanks.

---

<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:** [December 6, 2024, 9:27am UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/2 "2024-12-06T09:27:29Z")

</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:

> **[Order Fulfillments](https://developer.squareup.com/docs/orders-api/fulfillments)**
>
> Learn how to create and manage order fulfillment using the Square Orders API.

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

> **Additional Documentation**
>
> [Take a Pickup Order and Pay for It](https://developer.squareup.com/docs/orders-api/quick-start/step-4)  
> [Create Orders](https://developer.squareup.com/docs/orders-api/create-orders)  
> [Refund Payments](https://developer.squareup.com/docs/payments-api/refund-payments)

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:** ![lakshmi](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@lakshmi](https://developer.squareup.com/forums/u/lakshmi)\
**Post date:** [December 6, 2024, 10:16am UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/3 "2024-12-06T10:16:02Z")

</div>

To follow up on this-  
If I update the order with the fulfillment state to CANCELLED - the order remains in the OPEN state.  
If i then try to change the state of. the order to CANCELLED via the updateOrder- it still fails with the same error  
“detail”: “Orders cannot be canceled after payments have been processed.”,

However, on the square sandbox UI dashboard/orders/overview- i see the order state column mentions CANCELLED (although the retrieve order API call still says the order state is OPEN.  
Also, when i filter by orders on the UI- this order shows up in the “Upcoming” filter, and not in the cancelled filter.

 ![Screenshot 2024-12-06 at 11.13.27](https://global.discourse-cdn.com/square/original/2X/a/a1540b9a2dec669a0725668e6a68e38b92717547.png)

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 6, 2024, 6:14pm UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/4 "2024-12-06T18:14:50Z")

</div>

At this time canceling an order that has a payment isn’t currently available. The way Square cancels an order that’s paid for is we complete the order and refund the payment. 🙂

---

<div class="post-metadata">

**Author:** ![lakshmi](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@lakshmi](https://developer.squareup.com/forums/u/lakshmi)\
**Post date:** [December 6, 2024, 9:15pm UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/5 "2024-12-06T21:15:09Z")

</div>

Thank you for clarifying this.

In that case- would it make sense to cancel the fulfillment only? So the square user can see the order as cancelled on the dashboard?

We sometimes have orders that don’t have refunds or only a partial refund. How should we proceed in that case?

How does it work via the square dashboard when you click on cancel? The payment is refunded, but the order state also moves to Cancelled.  
If I refund the payment via the api- the original order state doesn’t change.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 6, 2024, 9:27pm UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/6 "2024-12-06T21:27:30Z")

</div>

Yes, sorry forgot to mention that we also cancel the fulfillment. 🙂

---

<div class="post-metadata">

**Author:** ![lakshmi](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@lakshmi](https://developer.squareup.com/forums/u/lakshmi)\
**Post date:** [February 3, 2025, 4:43pm UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/7 "2025-02-03T16:43:52Z")

</div>

I have a follow up on this-  
What happens to the inventory in this case?  
When i create an order, the inventory gets deducted correctly.  
How can i restock the inventory on canceling the order via the API?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [February 4, 2025, 4:37pm UTC](https://developer.squareup.com/forums/t/orders-api-cancel-an-order-via-the-api/19971/8 "2025-02-04T16:37:53Z")

</div>

With the [Inventory API](https://developer.squareup.com/docs/inventory-api/what-it-does) you can restock the deducted inventory. 🙂
