I am getting an error in cURL call for Price rule based on selected products.
Following is my error:
{
"errors":{
"price_rule":"Required parameter missing or invalid"
}
}
Following is my body parameters which I am sending in cURL call:
{
"price_rule":{
"title":"sss",
"target_type":"line_item",
"target_selection":"entitled",
"allocation_method":"across",
"value_type":"fixed_amount",
"value":"-434",
"customer_selection":"all",
"prerequisite_quantity_range":{
"greater_than_or_equal_to":"2"
},
"entitled_product_ids":{
"0":"2397130326093",
"1":"2397129965645",
"2":"2397131898957",
"3":"2397132324941"
},
"starts_at":"2019-02-22T08:08:53.000Z"
}
}
Following is my cURL call:
$ch = curl_init();
// curl_setopt($ch, CURLOPT_POST, count($newrule));
curl_setopt($ch, CURLOPT_URL, $access_token_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($pro_ids11));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Shopify-Access-Token: '.$shops_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}
curl_close($ch);
if (isset($error_msg)) {
echo $error_msg;
}
Please note that I am working in PHP.
Thanks in Advance!
4
Answers
entitled_product_ids should be in this format:
Also, the starts_at value should be in the ISO 8601 format (Note that one 0 is missing at the end):
Your format is wrong:
entitled_product_ids
should be an array and not an objectDocumentation for reference: https://help.shopify.com/en/api/reference/discounts/pricerule#create
Can you change your code like this
First : You need to send the data with
'Content-Type: application/json'
and be sure of thatSecond : You have to send
entitled_product_ids
as an array not an object