Cancel an order using API

Solved
ARAhmed
Tourist
6 0 1

I want to try cancelling an order by using respective API's .

Example resource:
https://APIKey:Password@development-store.myshopify.com/admin/orders/298312803/cancel.json

My JSON Post:
{"order":{"amount":"35.26","restock":true,"reason":"other","email":true}}

But we fails to cancel an order . I got a some error like (Internal Server Error). 

Anyone have some thoughts about my expectation. So, Please help me

Thanks in Advance.

Accepted Solution (1)

Accepted Solutions
awwdam
Shopify Staff
172 32 17

This is an accepted solution.

Hey @ARAhmed,

I was able to take a closer look, and through investigation I located some request logs. It appears the endpoint url didn’t quite match what we would usually expect and differs from the example shared above. While we don't have access to dig past these API logs, I have put together some resources, insights and suggestions to help moving forward: 

First, confirm that you are using the "id" of an order :
This is the ID of the order, used for API purposes and does not directly correlate to the order_name or order_number. This is different from the order_number property, that is used by the shop owner and customer." - more in our doc here. 

Next, use this "id" in the request URL. Example: /admin/api/2021-07/orders/{ORDER_ID}/cancel.json to test a request again - I'd also suggest logging any x-request-id, error codes, and response body in the case you are still unsuccessful or are getting an unexpected response.

Finally, if you are still facing issues I would suggest reporting an API bug with all of the info gathered in the steps I shared. You can do this through support if you are a merchant, or if you a partner please click the button provided in the Support menu of your Partner Dashboard, then select the 'Report an issue' option.

Hope you are able to get this sorted out - Cheers. 

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 7 (7)
awwdam
Shopify Staff
172 32 17

Hey @ARAhmed

Just wanted to confirm if the order you are intending to cancel is 1) already paid or if it 2) has any fulfillments - both of these factors would prevent the order from being cancelled via the API per the documentation here. If not, would you be able to share the x-request-id response header returned with the internal server error? This would allow my to take a closer look at our logs and pass back any insights or suggestions - Cheers.

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ARAhmed
Tourist
6 0 1

Hey @awwdam 

I confirm that payment status are pending and fulfillment status also Unfulfilled. But still we get same error Why.?

awwdam
Shopify Staff
172 32 17

Hey @ARAhmed, to take a closer look here I would need an x-request-id response header, with which I would be happy to dig deeper and pass back what I find - Best!


awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ARAhmed
Tourist
6 0 1

Hey @awwdam , This are my x-request-id (d36393cc-d656-49b4-8459-356220b7087d) . Kindly check here and help me out.

awwdam
Shopify Staff
172 32 17

This is an accepted solution.

Hey @ARAhmed,

I was able to take a closer look, and through investigation I located some request logs. It appears the endpoint url didn’t quite match what we would usually expect and differs from the example shared above. While we don't have access to dig past these API logs, I have put together some resources, insights and suggestions to help moving forward: 

First, confirm that you are using the "id" of an order :
This is the ID of the order, used for API purposes and does not directly correlate to the order_name or order_number. This is different from the order_number property, that is used by the shop owner and customer." - more in our doc here. 

Next, use this "id" in the request URL. Example: /admin/api/2021-07/orders/{ORDER_ID}/cancel.json to test a request again - I'd also suggest logging any x-request-id, error codes, and response body in the case you are still unsuccessful or are getting an unexpected response.

Finally, if you are still facing issues I would suggest reporting an API bug with all of the info gathered in the steps I shared. You can do this through support if you are a merchant, or if you a partner please click the button provided in the Support menu of your Partner Dashboard, then select the 'Report an issue' option.

Hope you are able to get this sorted out - Cheers. 

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

ARAhmed
Tourist
6 0 1

Hi @awwdam , Thank u so much for help. I get it my point.

AhmedRaza
New Member
3 0 0

Hi @awwdam I face some other problems . Customer have purchase two different products. But He want to cancel a one products. My problem is I can do that via API's.

Can you help me which value are required to pass API's Call. In Order cancellation case we pass a OrderID he can work fine. But we want to cancel only one product. How.?