New Shopify Certification now available: Liquid Storefronts for Theme Developers

How to cancel an Order's line item by using respective API?

Solved
Abubakar8144
New Member
11 0 0

I have an order with three line items. I want to cancel one line item. When I tried cancel one line item by using respective API, it cancelled the whole order. Kindly tell me how I can cancel one line item by using respective API?

 

 

Here is my example of cancel a whole order.

https://my development store.myshopify.com/admin/api/2021-10/orders/**bleep**/cancel.json

 

My Json request body:

{
    "order":{
        "order_id":**bleep**,
        "amount":"8400.00",
        "currency":"PKR",
        "email":true,
        "reason":"other",        
        "restock":true
    }
}
 
My objective is to cancel one line item by using respective API rather than canceling the whole order. Kindly help me in this problem.
Thanks in advance.
Accepted Solution (1)
csam
Shopify Staff (Retired)
Shopify Staff (Retired)
267 40 50

This is an accepted solution.

Hi @Abubakar8144 

 

You will want to use the refund_line_items field to specify the item(s) you want to cancel from the order. You can read more about refund fields here: https://shopify.dev/api/admin-rest/2021-10/resources/refund#[post]/admin/api/2021-10/orders/{order_i...

 

Regards,

 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 3 (3)
csam
Shopify Staff (Retired)
Shopify Staff (Retired)
267 40 50

This is an accepted solution.

Hi @Abubakar8144 

 

You will want to use the refund_line_items field to specify the item(s) you want to cancel from the order. You can read more about refund fields here: https://shopify.dev/api/admin-rest/2021-10/resources/refund#[post]/admin/api/2021-10/orders/{order_i...

 

Regards,

 

To learn more visit the Shopify Help Center or the Community Blog.

Abubakar8144
New Member
11 0 0

I have tried this refund_line_items field. It didn't work. It asks me to write the location_id but when I tried the get order call to see the location_id, it was set to null. Kindly tell me how I can get the location_id?

Abubakar8144
New Member
11 0 0

We can retrieve a list of locations and location id by using this API.

GET
https://my development store.myshopify.com/admin/api/2021-10/locations.json
 
For more information: