I am attempting to create a price rule using admin.rest.resource. the documentation states that the response will contain the created price rule. however, when I attempt to retrieve the response, it is returning undefined.
https://shopify.dev/docs/api/admin-rest/2024-01/resources/pricerule#post-price-rules
const price_rule = new admin.rest.resources.PriceRule({session: session});
price_rule.title = “TEST”;
price_rule.target_type = “line_item”;
price_rule.target_selection = “all”;
price_rule.allocation_method = “across”;
price_rule.value_type = “fixed_amount”;
price_rule.value = “-10.0”;
price_rule.customer_selection = “all”;
price_rule.starts_at = “2018-03-22T00:00:00-00:00”;
const priceResponse = await price_rule.save({
update: true,
});
console.log(‘priceResponse:’+JSON.stringify(priceResponse));
I have also tried just logging the response without using a variable:
console.log(‘save:’+JSON.stringify(await price_rule.save({
update: true,
})));
it also returns undefined.
Both of these will create the price rule and I can retrieve it if i list all the price rules:
console.log(‘price rule list:’+JSON.stringify(await admin.rest.resources.PriceRule.all({
session: session,
})));
How do I get the id of the created price rule so I can use it in creating a discount code? I don’t want to query the price rules every time i want to create a discount and loop over those trying to find my newly created price rule.
Thanks