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 |
---|---|
6 | |
5 | |
5 | |
5 | |
4 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022