"Required parameter missing or invalid" error when creating an order

Solved

"Required parameter missing or invalid" error when creating an order

Development_Te3
Tourist
3 1 3

Hi there,

 

I'm running into an issue where I am able to POST an order to Shopify through Postman, but when I try to recreate it in my app I get the following error:

 

{"errors":{"order":"Required parameter missing or invalid"}}

Below is my code:

var testOrder = {
		"order": {
			"email": "email10+TEST@gmail.com",
			"shipping_address":
				{ "address1": "10 Erb St.",
					"city": "Toronto",
					"province": "ON",
					"country": "CA",
					"zip": "N2N 1N5",
					"company": null,
					"first_name": "JOE",
					"last_name": "TEST" },
			"phone": null,
			"line_items": [
				{
					"variant_id": 42331988931,
					"price": "300.0",
					"quantity": 1
				}
			],
			"discount_codes": [ { "code": "25%OFF", "amount": "25", "type": "percentage" } ],
			"tags": "27900202",
			"note": "test",
			"shipping_lines": [ { "title": "test", "price": "30.00", "code": "test" } ],
			"total_tax": "25.5"
		}
	};

	var shopifyOrderOptions = {
		url: "https://{apikey}:{password}@{site}.myshopify.com/admin/api/2019-07/orders.json",
		headers : { 'Content-Type': 'application/json' },
		data: testOrder

	request.post(shopifyOrderOptions, (err, res, body) => {
		if (err) { console.log(err); }
		console.log(body);
	});

Please let me know what I'm doing wrong. Thanks!

 

 

 

Accepted Solution (1)
Development_Te3
Tourist
3 1 3

This is an accepted solution.

Nevermind, I just had to change the 'data' parameter to 'body' and JSON.stringify() the value. It now posts sucessfully.

View solution in original post

Replies 4 (4)

oscprofessional
Shopify Partner
15938 2383 3092

Hello 

 

Please refer the below link ;-

https://help.shopify.com/en/api/reference/orders/order#index-2019-07

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free
Development_Te3
Tourist
3 1 3

Hi Pallavi,

 

I've been referring to this Order API documentation as well as the general API docs, and I may be missing something but I've been having trouble finding out how to properly format the request along with the correct headers, authentication, etc. I'm assuming this is what is giving me the error as it's successfully posting via Postman but not in my app. Or perhaps it's how I'm using the Request HTTP client. Would you be able to possibly shed some light on this? Sorry I should have been more specific in my initial question.

 

Thanks!

 

Development_Te3
Tourist
3 1 3

This is an accepted solution.

Nevermind, I just had to change the 'data' parameter to 'body' and JSON.stringify() the value. It now posts sucessfully.

steamroller
Shopify Partner
8 0 4

For Googlers, remember that your API client (i.e. Postman) might not be formatting your body the way Shopify wants it, by default.  (data-raw, etc.) Beware of the CURL gotchas with Postman if you are reading the CURL examples in the Shopify docs.