Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error In API cURL Call: {"errors":{"price_rule":"Required parameter missing or invalid"}}

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!

like image 360
Vikas Ghai Avatar asked Dec 23 '22 00:12

Vikas Ghai


1 Answers

Can you change your code like this

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, TRUE);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($curl, CURLOPT_MAXREDIRS, 3);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($curl, CURLOPT_USERAGENT, 'My New Shopify App v.1');
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');

    // Setup headers
    $request_headers[] = "X-Shopify-Access-Token: " . $token;
    $request_headers[]='Content-Type: application/json'

    curl_setopt($curl, CURLOPT_HTTPHEADER, $request_headers);  
    $query = json_encode($query);
    curl_setopt ($curl, CURLOPT_POSTFIELDS, $query);
    $result = curl_exec($ch);
like image 200
Jigar Avatar answered Jan 13 '23 12:01

Jigar