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 |
---|---|
57 | |
11 | |
8 | |
6 | |
6 |
Thanks to all who participated in our AMA with 2H Media on planning your 2023 marketing bu...
By Jacqui Mar 30, 2023Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023