I can't create price rule.

Solved
Highlighted
Shopify Partner
12 0 1

I want to make a new price rule but I can't. 

Can someone give me some advise please?

Below is the code.

 

  shop = ShopifyAPI::Shop.current
  puts shop.inspect
 
  pricerule = ShopifyAPI::PriceRule.new({:value => -100, :title =>"aaa"})
  pricerule.save
 
  pricerules = ShopifyAPI::PriceRule.find(:all)
  puts pricerules.inspect
 
I can fetch data of "shop", but I can't get data of Price Rule. "pricerules" are empty.
Can someone let me know what is wrong with this code?
 
0 Likes
Highlighted
Shopify Partner
1840 177 707

This is an accepted solution.

You are missing a tonne of required fields for a price rule.

 

  • value_type
  • target_type
  • target_selection
  • allocation_method
  • starts_at
  • customer_selection

I suggest you read the API docs. And if the Ruby SDK isn't returning the 422 response with errors, then try your requests in any regular HTTP REST client such as Postman, Insomnia or even good ol' cURL will give you a heads up.

Liked this post? You might also like our fantastic upsell apps Candy Rack and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Highlighted
Shopify Partner
12 0 1

Thank you very much!

I missed the require field!

You helped me a lot!!

0 Likes
Highlighted
New Member
1 0 0

When i am trying to hit the rest api to create priceRule then it was throwing a 403 error i.e. forbidden error.

0 Likes