Development discussions around Shopify APIs
Hi guys,
Whenever I try to create an order through the API with "shipping_address" it fails. However without shipping_address, the order is processed correctly.
For example, making the following query in a POST request to /admin/api/2021-01/orders.json returns HTTP/1.1 400 Bad Request:
{"order": {"email": "email@domain.com", "send_receipt": false, "send_fulfillment_receipt": true, "note": "Customer note if applicable", "inventory_behaviour": "decrement_obeying_policy", "line_items": [{"variant_id": 39290503954631, "quantity": 1}, {"variant_id": 39384463212743, "quantity": 2}, {"title": "DIFFAIR Order number 1234567", "price": 0, "quantity": 1, "variant_title": "Customer Name, Address1, Address2, 8000 City"}], "shipping_lines": [{"price": 9, "title": "DIFFAIR Market"}], "shipping_address": [{"first_name": "Bob", "last_name": "Who", "address1": "Fake Street 92", "address2": "", "city": "Louisville", "zip": "40202", "country": "United States"}] }}
But the same request with the "shipping_address" works:
{"order": {"email": "email@domain.com", "send_receipt": false, "send_fulfillment_receipt": true, "note": "Customer note if applicable", "inventory_behaviour": "decrement_obeying_policy", "line_items": [{"variant_id": 39290503954631, "quantity": 1}, {"variant_id": 39384463212743, "quantity": 2}, {"title": "DIFFAIR Order number 1234567", "price": 0, "quantity": 1, "variant_title": "Customer Name, Address1, Address2, 8000 City"}], "shipping_lines": [{"price": 9, "title": "DIFFAIR Market"}] }}
The 400 error code seems like a formatting issue, but I can't figure it out.
Anyone seen this behaviour or can see my mistake?
Thanks,
Daniel
Solved! Go to the solution
This is an accepted solution.
Oops, I found the error. There should be no square brackets around the shipping_address value.
This works as expected:
{"order": {"email": "email@domain.com", "send_receipt": false, "send_fulfillment_receipt": true, "note": "Customer note if applicable", "inventory_behaviour": "decrement_obeying_policy", "line_items": [{"variant_id": 39290503954631, "quantity": 1}, {"variant_id": 39384463212743, "quantity": 2}, {"title": "DIFFAIR Order number 1234567", "price": 0, "quantity": 1, "variant_title": "Customer Name, Address1, Address2, 8000 City"}], "shipping_lines": [{"price": 9, "title": "DIFFAIR Market"}], "shipping_address": {"first_name": "Bob", "last_name": "Who", "address1": "Fake Street 92", "address2": "", "city": "Louisville", "zip": "40202", "country": "United States"} }}
I guess it helps to lay out the problem clearly 😄
This is an accepted solution.
Oops, I found the error. There should be no square brackets around the shipping_address value.
This works as expected:
{"order": {"email": "email@domain.com", "send_receipt": false, "send_fulfillment_receipt": true, "note": "Customer note if applicable", "inventory_behaviour": "decrement_obeying_policy", "line_items": [{"variant_id": 39290503954631, "quantity": 1}, {"variant_id": 39384463212743, "quantity": 2}, {"title": "DIFFAIR Order number 1234567", "price": 0, "quantity": 1, "variant_title": "Customer Name, Address1, Address2, 8000 City"}], "shipping_lines": [{"price": 9, "title": "DIFFAIR Market"}], "shipping_address": {"first_name": "Bob", "last_name": "Who", "address1": "Fake Street 92", "address2": "", "city": "Louisville", "zip": "40202", "country": "United States"} }}
I guess it helps to lay out the problem clearly 😄
User | RANK |
---|---|
10 | |
5 | |
3 | |
3 | |
3 |
Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023Summary of EventsBeginning in January of 2023, some merchants reported seeing a large amo...
By Trevor May 15, 2023