Shopify API - How To Cancel An Order And Retrieve A List Of Canceled Orders Using Postman

Shopify API – How To Cancel An Order And Retrieve A List Of Canceled Orders Using Postman

There are many reasons lead-in cancel an order. If the customer buys the wrong items, the items which the customer wants to buy are sold out, fraudulent customers, or the customer wants to cancel an order. In those cases, the admin can cancel an order if meeting one in two conditions:

  • The order isn’t paid 
  • The order isn’t the fulfillment

Cancel an order is necessary for an admin. Because this activity happens frequently. If the admin doesn’t cancel the order, inventory, revenue, and customers indicators will be wrong. Besides, if you need data to report or evaluate your business, a complete list of canceled orders is certainly what you need.

So this is a reason, today Beehexa will show you how to cancel an order and retrieve a list of canceled orders when you need it using Postman. 

Let’s explore one by one in this article.

Cancel An Order Using Postman

Step 1: Generate API credentials from the Shopify admin

Generate API credentials from the Shopify admin
  • Click Create a new private app
  • In the App details section, enter a name for your app, and an emergency developer email
  • In the Admin API section, select the areas of your store that you want the app to access
Generate API credentials from the Shopify admin
  • Click Save

The Admin API section displays the app’s API key and password when you save the app’s details. 

Step 2: Cancel An Order Using Postman

  • Log in to your Postman and create a new workspace
  • Create a new POST with this URL:
https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json
Code language: JavaScript (javascript)
  1. {username} – The API key that you generated.
  2. {password} – The API password that you generated.
  3. {shop} – The name of your development store.
  4. {api-version} – The supported API version that you want to use.
  5. {resource} – A resource endpoint from the REST Admin API.

Or you can copy this example in the Shopify Admin, remember change {resource} to {orders/order_id/cancel}:

https://33a72f01e02987636e1c1a9a4e95c840:[email protected]/admin/api/2022-01/orders/4253998743615/cancel.json
Code language: JavaScript (javascript)

order_id=4253998743615

You can read Shopify API – Create An Order Using Postman blog to get the order_id, or you can follow this process to get the order_id:

  1. In the admin dashboard, choose orders, then click all orders.
  2. Choose the order you want to cancel.
  3. Copy the order_id in the URL 
Example URL

Paste the URL above.

post

Then click Send

Response:

The API will return all information about the canceled order.

{ "order": { "id": 4253998743615, "admin_graphql_api_id": "gid://shopify/Order/4253998743615", "app_id": 580111, "browser_ip": "117.2.168.124", "buyer_accepts_marketing": false, "cancel_reason": null, "cancelled_at": null, "cart_token": "1b2f234db70a95824ced7ccca61b85cf", "checkout_id": 25714793807935, "checkout_token": "7a80210bcb29bfd8656510b44f41e442", "client_details": { "accept_language": "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5", "browser_height": 754, "browser_ip": "117.2.168.124", "browser_width": 1519, "session_hash": null, "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" }, "closed_at": null, "confirmed": true, "contact_email": "[email protected]", "created_at": "2022-01-11T19:19:59+09:00", "currency": "AUD", "current_subtotal_price": "77.00", "current_subtotal_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "current_total_discounts": "0.00", "current_total_discounts_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "current_total_duties_set": null, "current_total_price": "77.00", "current_total_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "current_total_tax": "0.00", "current_total_tax_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "customer_locale": "en", "device_id": null, "discount_codes": [], "email": "[email protected]", "estimated_taxes": false, "financial_status": "pending", "fulfillment_status": null, "gateway": "Cash on Delivery (COD)", "landing_site": "/", "landing_site_ref": null, "location_id": null, "name": "#1173", "note": null, "note_attributes": [], "number": 173, "order_number": 1173, "order_status_url": "https://hexasync.myshopify.com/25322618943/orders/40f5302caa7be20e4dc75fc0b2bc3f09/authenticate?key=ccbe4af91744e786069c7c166968e91e", "original_total_duties_set": null, "payment_gateway_names": [ "Cash on Delivery (COD)" ], "phone": null, "presentment_currency": "AUD", "processed_at": "2022-01-11T19:19:58+09:00", "processing_method": "manual", "reference": null, "referring_site": "", "source_identifier": null, "source_name": "web", "source_url": null, "subtotal_price": "77.00", "subtotal_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "tags": "", "tax_lines": [], "taxes_included": false, "test": false, "token": "40f5302caa7be20e4dc75fc0b2bc3f09", "total_discounts": "0.00", "total_discounts_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "total_line_items_price": "77.00", "total_line_items_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "total_outstanding": "77.00", "total_price": "77.00", "total_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "total_price_usd": "55.27", "total_shipping_price_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "total_tax": "0.00", "total_tax_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "total_tip_received": "0.00", "total_weight": 0, "updated_at": "2022-01-11T19:20:00+09:00", "user_id": null, "billing_address": { "first_name": "Yushin", "address1": "1925 Washington Street", "phone": "(361) 386-5113", "city": "Hollywood", "zip": "33020", "province": "Florida", "country": "United States", "last_name": "Lam", "address2": "", "company": "Beehexa", "latitude": 26.004309, "longitude": -80.14562769999999, "name": "Yushin Lam", "country_code": "US", "province_code": "FL" }, "customer": { "id": 5484387270719, "email": "[email protected]", "accepts_marketing": false, "created_at": "2021-11-08T18:13:34+09:00", "updated_at": "2022-01-12T13:33:44+09:00", "first_name": "Hoai", "last_name": "Lam", "orders_count": 1, "state": "enabled", "total_spent": "77.00", "last_order_id": 4253998743615, "note": null, "verified_email": false, "multipass_identifier": null, "tax_exempt": false, "phone": null, "tags": "", "last_order_name": "#1173", "currency": "AUD", "accepts_marketing_updated_at": "2021-11-08T18:13:35+09:00", "marketing_opt_in_level": null, "tax_exemptions": [], "sms_marketing_consent": null, "admin_graphql_api_id": "gid://shopify/Customer/5484387270719", "default_address": { "id": 6833735827519, "customer_id": 5484387270719, "first_name": "Yushin", "last_name": "Lam", "company": "Beehexa", "address1": "1925 Washington Street", "address2": "", "city": "Hollywood", "province": "Florida", "country": "United States", "zip": "33020", "phone": "(361) 386-5113", "name": "Yushin Lam", "province_code": "FL", "country_code": "US", "country_name": "United States", "default": true } }, "discount_applications": [], "fulfillments": [], "line_items": [ { "id": 10871191633983, "admin_graphql_api_id": "gid://shopify/LineItem/10871191633983", "fulfillable_quantity": 1, "fulfillment_service": "manual", "fulfillment_status": null, "gift_card": false, "grams": 0, "name": "Eddy Insulated Bottle .5L", "origin_location": { "id": 3140898455615, "country_code": "VN", "province_code": "", "name": "Hexasync Demo Storefront", "address1": "428 Dien Bien Phu Ward 11 District 10", "address2": "", "city": "Ho Chi Minh City", "zip": "700000" }, "price": "20.00", "price_set": { "shop_money": { "amount": "20.00", "currency_code": "AUD" }, "presentment_money": { "amount": "20.00", "currency_code": "AUD" } }, "product_exists": true, "product_id": 4356041867327, "properties": [], "quantity": 1, "requires_shipping": true, "sku": "CONBOTTLE1", "taxable": true, "title": "Eddy Insulated Bottle .5L", "total_discount": "0.00", "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "variant_id": 31179493703743, "variant_inventory_management": "shopify", "variant_title": "", "vendor": "hexasync", "tax_lines": [], "duties": [], "discount_allocations": [] }, { "id": 10871191666751, "admin_graphql_api_id": "gid://shopify/LineItem/10871191666751", "fulfillable_quantity": 1, "fulfillment_service": "manual", "fulfillment_status": null, "gift_card": false, "grams": 0, "name": "Alum Telescoping Flag Pole", "origin_location": { "id": 3140898455615, "country_code": "VN", "province_code": "", "name": "Hexasync Demo Storefront", "address1": "428 Dien Bien Phu Ward 11 District 10", "address2": "", "city": "Ho Chi Minh City", "zip": "700000" }, "price": "57.00", "price_set": { "shop_money": { "amount": "57.00", "currency_code": "AUD" }, "presentment_money": { "amount": "57.00", "currency_code": "AUD" } }, "product_exists": true, "product_id": 4356050649151, "properties": [], "quantity": 1, "requires_shipping": true, "sku": "CONFLAGPL", "taxable": true, "title": "Alum Telescoping Flag Pole", "total_discount": "0.00", "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "variant_id": 31179512315967, "variant_inventory_management": "shopify", "variant_title": "", "vendor": "hexasync", "tax_lines": [], "duties": [], "discount_allocations": [] } ], "payment_terms": null, "refunds": [], "shipping_address": { "first_name": "Yushin", "address1": "1925 Washington Street", "phone": "(361) 386-5113", "city": "Hollywood", "zip": "33020", "province": "Florida", "country": "United States", "last_name": "Lam", "address2": "", "company": "Beehexa", "latitude": 26.004309, "longitude": -80.14562769999999, "name": "Yushin Lam", "country_code": "US", "province_code": "FL" }, "shipping_lines": [ { "id": 3607447240767, "carrier_identifier": null, "code": "Standard", "delivery_category": null, "discounted_price": "0.00", "discounted_price_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "phone": null, "price": "0.00", "price_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "requested_fulfillment_service_id": null, "source": "shopify", "title": "Standard", "tax_lines": [], "discount_allocations": [] } ] }, "notice": "Order has been canceled" }
Code language: JSON / JSON with Comments (json)
response

Step 3: Verify The Result

In the admin, choose orders, click all orders.

canceled

As you can see, the order is crossed out, indicating that the order was canceled successfully.

After this step, the admin needs to stop the fulfillment process (select product, package, delivery product for shipper,…) manually, because canceling an order using Postman or Shopify is not linked with the fulfillment process. 

Retrieve A List Of Canceled Orders

In Shopify dev docs, the document doesn’t show you how to retrieve a list of canceled orders. But in this article, Beehexa will guide you step by step to get the data of cancel order when you need it.

Step 1: Generate API credentials from the Shopify admin

Generate API credentials from the Shopify admin
  • Click Create a new private app
  • In the App details section, enter a name for your app, and an emergency developer email
  • In the Admin API section, select the areas of your store that you want the app to access
Generate API credentials from the Shopify admin
  • Click Save

The Admin API section displays the app’s API key and password when you save the app’s details. 

Step 2: Retrieve A List Of Canceled Orders Using Postman

  • Log in to your Postman and create a new workspace
  • Create a new GET with this URL:
https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json
Code language: JavaScript (javascript)
  1. {username} – The API key that you generated.
  2. {password} – The API password that you generated.
  3. {shop} – The name of your development store.
  4. {api-version} – The supported API version that you want to use.
  5. {resource} – A resource endpoint from the REST Admin API.

Or you can copy this example in the Shopify Admin, remember change {resource.json} to {orders.json?status=cancelled}:

https://33a72f01e02987636e1c1a9a4e95c840:[email protected]/admin/api/2022-01/orders.json?status=cancelled
Code language: JavaScript (javascript)
Example URL

Paste the URL above.

GET

Then click Send

Response:

The API will return the list of canceled orders.

{ "orders": [ { "id": 4253998743615, "admin_graphql_api_id": "gid://shopify/Order/4253998743615", "app_id": 580111, "browser_ip": "117.2.168.124", "buyer_accepts_marketing": false, "cancel_reason": "other", "cancelled_at": "2022-01-12T13:45:03+09:00", "cart_token": "1b2f234db70a95824ced7ccca61b85cf", "checkout_id": 25714793807935, "checkout_token": "7a80210bcb29bfd8656510b44f41e442", "client_details": { "accept_language": "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5", "browser_height": 754, "browser_ip": "117.2.168.124", "browser_width": 1519, "session_hash": null, "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" }, "closed_at": null, "confirmed": true, "contact_email": "[email protected]", "created_at": "2022-01-11T19:19:59+09:00", "currency": "AUD", "current_subtotal_price": "77.00", "current_subtotal_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "current_total_discounts": "0.00", "current_total_discounts_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "current_total_duties_set": null, "current_total_price": "77.00", "current_total_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "current_total_tax": "0.00", "current_total_tax_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "customer_locale": "en", "device_id": null, "discount_codes": [], "email": "[email protected]", "estimated_taxes": false, "financial_status": "pending", "fulfillment_status": null, "gateway": "Cash on Delivery (COD)", "landing_site": "/", "landing_site_ref": null, "location_id": null, "name": "#1173", "note": null, "note_attributes": [], "number": 173, "order_number": 1173, "order_status_url": "https://hexasync.myshopify.com/25322618943/orders/40f5302caa7be20e4dc75fc0b2bc3f09/authenticate?key=ccbe4af91744e786069c7c166968e91e", "original_total_duties_set": null, "payment_gateway_names": [ "Cash on Delivery (COD)" ], "phone": null, "presentment_currency": "AUD", "processed_at": "2022-01-11T19:19:58+09:00", "processing_method": "manual", "reference": null, "referring_site": "", "source_identifier": null, "source_name": "web", "source_url": null, "subtotal_price": "77.00", "subtotal_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "tags": "", "tax_lines": [], "taxes_included": false, "test": false, "token": "40f5302caa7be20e4dc75fc0b2bc3f09", "total_discounts": "0.00", "total_discounts_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "total_line_items_price": "77.00", "total_line_items_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "total_outstanding": "77.00", "total_price": "77.00", "total_price_set": { "shop_money": { "amount": "77.00", "currency_code": "AUD" }, "presentment_money": { "amount": "77.00", "currency_code": "AUD" } }, "total_price_usd": "55.27", "total_shipping_price_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "total_tax": "0.00", "total_tax_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "total_tip_received": "0.00", "total_weight": 0, "updated_at": "2022-01-12T13:45:03+09:00", "user_id": null, "billing_address": { "first_name": "Yushin", "address1": "1925 Washington Street", "phone": "(361) 386-5113", "city": "Hollywood", "zip": "33020", "province": "Florida", "country": "United States", "last_name": "Lam", "address2": "", "company": "Beehexa", "latitude": 26.004309, "longitude": -80.14562769999999, "name": "Yushin Lam", "country_code": "US", "province_code": "FL" }, "customer": { "id": 5484387270719, "email": "[email protected]", "accepts_marketing": false, "created_at": "2021-11-08T18:13:34+09:00", "updated_at": "2022-01-12T13:33:44+09:00", "first_name": "Hoai", "last_name": "Lam", "orders_count": 1, "state": "enabled", "total_spent": "77.00", "last_order_id": 4253998743615, "note": null, "verified_email": false, "multipass_identifier": null, "tax_exempt": false, "phone": null, "tags": "", "last_order_name": "#1173", "currency": "AUD", "accepts_marketing_updated_at": "2021-11-08T18:13:35+09:00", "marketing_opt_in_level": null, "tax_exemptions": [], "sms_marketing_consent": null, "admin_graphql_api_id": "gid://shopify/Customer/5484387270719", "default_address": { "id": 6833735827519, "customer_id": 5484387270719, "first_name": "Yushin", "last_name": "Lam", "company": "Beehexa", "address1": "1925 Washington Street", "address2": "", "city": "Hollywood", "province": "Florida", "country": "United States", "zip": "33020", "phone": "(361) 386-5113", "name": "Yushin Lam", "province_code": "FL", "country_code": "US", "country_name": "United States", "default": true } }, "discount_applications": [], "fulfillments": [], "line_items": [ { "id": 10871191633983, "admin_graphql_api_id": "gid://shopify/LineItem/10871191633983", "fulfillable_quantity": 1, "fulfillment_service": "manual", "fulfillment_status": null, "gift_card": false, "grams": 0, "name": "Eddy Insulated Bottle .5L", "origin_location": { "id": 3140898455615, "country_code": "VN", "province_code": "", "name": "Hexasync Demo Storefront", "address1": "428 Dien Bien Phu Ward 11 District 10", "address2": "", "city": "Ho Chi Minh City", "zip": "700000" }, "price": "20.00", "price_set": { "shop_money": { "amount": "20.00", "currency_code": "AUD" }, "presentment_money": { "amount": "20.00", "currency_code": "AUD" } }, "product_exists": true, "product_id": 4356041867327, "properties": [], "quantity": 1, "requires_shipping": true, "sku": "CONBOTTLE1", "taxable": true, "title": "Eddy Insulated Bottle .5L", "total_discount": "0.00", "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "variant_id": 31179493703743, "variant_inventory_management": "shopify", "variant_title": "", "vendor": "hexasync", "tax_lines": [], "duties": [], "discount_allocations": [] }, { "id": 10871191666751, "admin_graphql_api_id": "gid://shopify/LineItem/10871191666751", "fulfillable_quantity": 1, "fulfillment_service": "manual", "fulfillment_status": null, "gift_card": false, "grams": 0, "name": "Alum Telescoping Flag Pole", "origin_location": { "id": 3140898455615, "country_code": "VN", "province_code": "", "name": "Hexasync Demo Storefront", "address1": "428 Dien Bien Phu Ward 11 District 10", "address2": "", "city": "Ho Chi Minh City", "zip": "700000" }, "price": "57.00", "price_set": { "shop_money": { "amount": "57.00", "currency_code": "AUD" }, "presentment_money": { "amount": "57.00", "currency_code": "AUD" } }, "product_exists": true, "product_id": 4356050649151, "properties": [], "quantity": 1, "requires_shipping": true, "sku": "CONFLAGPL", "taxable": true, "title": "Alum Telescoping Flag Pole", "total_discount": "0.00", "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "variant_id": 31179512315967, "variant_inventory_management": "shopify", "variant_title": "", "vendor": "hexasync", "tax_lines": [], "duties": [], "discount_allocations": [] } ], "payment_terms": null, "refunds": [], "shipping_address": { "first_name": "Yushin", "address1": "1925 Washington Street", "phone": "(361) 386-5113", "city": "Hollywood", "zip": "33020", "province": "Florida", "country": "United States", "last_name": "Lam", "address2": "", "company": "Beehexa", "latitude": 26.004309, "longitude": -80.14562769999999, "name": "Yushin Lam", "country_code": "US", "province_code": "FL" }, "shipping_lines": [ { "id": 3607447240767, "carrier_identifier": null, "code": "Standard", "delivery_category": null, "discounted_price": "0.00", "discounted_price_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "phone": null, "price": "0.00", "price_set": { "shop_money": { "amount": "0.00", "currency_code": "AUD" }, "presentment_money": { "amount": "0.00", "currency_code": "AUD" } }, "requested_fulfillment_service_id": null, "source": "shopify", "title": "Standard", "tax_lines": [], "discount_allocations": [] } ] } ] }
Code language: JSON / JSON with Comments (json)
GET

Above are all steps to cancel an order and retrieve a list of canceled orders with Shopify API using Postman. If you have any questions, please leave a comment below or refer to our Devdocs

If you still do not understand the tutorial’s content, you can watch the video below for a more overview.

Shopify API – How To Cancel An Order And Retrieve A List Of Canceled Orders Using Postman

Hopefully, you can do it!

Related Articles

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email