Unable to create orders by using POST /admin/api/2022-07/orders.json

I am trying to create a new order using the POST /admin/api/2022-07/orders.json API, but instead of giving the response 201 Created, the API is responding with the list of orders and Status code 200.

Here are the details:

URL = “https://XXXXXXX/admin/api/2022-07/orders.json

method: POST

Headers = {
‘X-Shopify-Access-Token’: ‘shppa_XXXXXXX’,
‘Content-Type’: ‘application/json’,
}

Payload =

{
“order”: {
“line_items”: [
{
“variant_id”: 42858663051445,
“quantity”: 1
}
],
“customer”: {
“first_name”: “John”,
“last_name”: “Doe”,
“email”: [email removed]
},
“financial_status”: “paid”
}
}

I have checked that I have got the necessary permission of read and write orders.

Hi @namansharma , you should follow the steps here https://shopify.dev/docs/api/admin-rest/2023-04/resources/order#post-orders, using a POST to that endpoint with a json content type should create an Order. The results you are describing seem to suggest it is a GET request that is being made. Perhaps you can test this in a client like Postman.

1 Like

Hello!

Thanks for the response but I am doing exactly the same as described in https://shopify.dev/docs/api/admin-rest/2022-07/resources/order#post-orders but the response is not ideal.

Here is the postman screenshot showing it is a a POST request and the response received with status code 200 and a list of orders.

Kindly, let me know if there is anything that I am missing.

Cheers!

Hi @namansharma , the screenshot is very small, but the endpoint seems correct. We would advise first trying to create a simple test order with minimal Body details using the API as per the example in the curl docs here. Remember to save in Postman and once you have that working try adding more details to the body until it matches your requirements or reveals an error. Alternatively if you continue to be stuck with this you can reach out to our Support team with the x-request-id from the response headers and we can investigate in our logs with some more detail. Hope this helps!

Hi there, did you find the solution? I have the same problem. Please let know

No.
I did what was suggested to me in the previous post. I contacted the support team with the X -Request Id and other details. However, I am yet to receive a resolution for the same as the case is been looked into.

I also contacted support. But they haven’t told me a solution yet. It doesn’t make sense that the request responses with status 200. The documentation doesn’t mention anything about that.

I found the solution. You probably use a custom domain name, let’s say: “myshop.com” so in your request I imagine you use:
https://myshop.com/admin/api/2023-04/orders.json

That’s the mistake. Unfortunately postman don’t warn us about that but the request actually is returning a 301 redirect. So apparently the default response after the redirect is a GET. I don’t know why. The way I noticed the error was by executing the request via CURL in the terminal.

Do the POST request in the terminal and you will see something like this:

curl -i -X POST -H “Content-Type: application/json” -H "X-Shopify-Access-Token: " -d ‘{“order”:{“line_items”:[{“variant_id”: ,“quantity”:1}],“customer”:{“id”: },“financial_status”:“pending”}}’ https://myshop.com/admin/api/2023-04/orders.json

HTTP/2 301

date: Fri, 07 Jul 2023 03:15:44 GMT

content-type: text/html; charset=utf-8

location: https://realdomain.myshopify.com/admin/api/2023-04/orders.json

So replace “myshop.com” with “realdomain.myshopify.com” and it will work!!

Happy coding.

Thanks. It worked. :grinning_face_with_smiling_eyes: