REST Price Rule: required parameter missing or invalid

Solved
Highlighted
Tourist
11 0 1

Apologies for posting something so common but the error (required parameter missing or invalid) is completely unhelpful and I've run out of permutations to try.

 

Here's my args dict:

 

pr_args = {
"title": "FNF",
"target_type": "line_item",
"target_selection": "all",
"allocation_method": "each",
"value_type": "percentage",
"value": "-50",
"once_per_customer": "false",
"customer_selection": "all",
"usage_limit": "1",
"starts_at": "2019-10-14T23:01:57Z"
}

This is being called with:

def post_price_rule(payload, type='price_rules.json'):
	req = requests.post(url=f'https://{KEY}:{PWD}@{SHOP_NAME}.myshopify.com/admin/api/{API_VERSION}/{type}',
                        json=payload, headers={'Content-Type': 'application/json'})
	print(req.content)
	return req.status_code

print(post_price_rule(pr_args, 'price_rules.json'))

... which produces the error above.

 

Any idea which part of the incantation I'm missing / malforming?

 

Thanks in advance.

 

0 Likes

Success.

Shopify Partner
927 96 149

Looks like the JSON is incorrect in your payload. You have to have all your attributes under "price_rule" attribute, and example would be:

{
  "price_rule": {
    "title": "SUMMERSALE10OFF",
    "target_type": "line_item",
    "target_selection": "all",
    "allocation_method": "across",
    "value_type": "fixed_amount",
    "value": "-10.0",
    "customer_selection": "all",
    "starts_at": "2017-01-19T17:59:10Z"
  }
}
Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Tourist
11 0 1

giphy

 

Thank you sir!! Just absolutely missed the forest for the trees.

0 Likes