Creating Price rules ajax status 303 or 400

Developer07
New Member
2 0 0

Hello!

I'm trying to create a price rule using the Admin API from the documentation, but I have a problem: I get a strange 303 status on post request. If I add contentType: "application / json" I get 400 bad request. Please tell me what could be the problem? Thank you.

Code (with test static post data):

$.ajax({
url: '/admin/api/2021-01/price_rules.json',
contentType: "application/json",
type: 'POST',
data: {
"price_rule": {
"title": "TESTDISCOUNT",
"target_type": "line_item",
"target_selection": "all",
"allocation_method": "across",
"value_type": "fixed_amount",
"value": "-10.0",
"customer_selection": "all",
"starts_at": "2020-01-19T17:59:10Z"
}
},
success: function (response) {
setTimeout(function () {
console.log(response);
},
error: function(xhr) {
console.log('xhr', xhr);
}
})

 

0 Likes
gina-gregory
Shopify Expert
669 39 145

You can't use the Admin API on the front-end with an Ajax request. You need an app that can properly authenticate on the back-end.

0 Likes
Developer07
New Member
2 0 0

Thank you for answer. Are you sure? GET request works very well.

0 Likes