Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

REST API order creation, 400 Bad Request

Solved

REST API order creation, 400 Bad Request

daniel832
Visitor
2 1 0

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

Accepted Solution (1)

daniel832
Visitor
2 1 0

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 😄

View solution in original post

Reply 1 (1)

daniel832
Visitor
2 1 0

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 😄