Happening now | Office Hours: Customizing Your Theme With Moeed | Ask your questions now!

Unable to create orders using admin API. I am receiving orders instead of order

Solved

Unable to create orders using admin API. I am receiving orders instead of order

javitek
Tourist
5 2 0

I am trying to create an order using post man. Considere that I am truly using POST instead of GET. 

Screen Shot 2023-07-06 at 4.36.30 PM.png

 The error as you can see is that the request responses with status 200 and the body is orders instead of order. And the order is not created. 

 

Is there anyone here that knows when happens this kind of things? The API should be more descriptive with the error responses.

 

Fact: I have used the same payload with another store and it works. I have the write_order permission in mi developer app. What am I missing in mi configuration?

Accepted Solution (1)

javitek
Tourist
5 2 0

This is an accepted solution.

I found the solution. I am using a custom domain name, let's say: "myshop.com" so in my request I 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!!

View solution in original post

Reply 1 (1)

javitek
Tourist
5 2 0

This is an accepted solution.

I found the solution. I am using a custom domain name, let's say: "myshop.com" so in my request I 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!!