Hello Please help me for this error!
I am getting error while making Price rule through curl.
$newrule= [ "price_rule"=> [ "title" => "sdad", "target_type" => "line_item", "target_selection" => "all", "allocation_method" => "across", "value_type" => "fixed_amount", "value" => "-10.0", "customer_selection" => "all", "starts_at" => "2017-01-19T17:59:10Z" ] ]; // Generate access token URL $access_token_url = "https://" . $req->shop . "/admin/price_rules.json"; // echo $access_token_url; die; $storename=explode('.',$req->shop); $getuser=User::where('name', $storename[0])->first(); $is_user = $getuser->count(); if($is_user>0){ $shops_token =$getuser->access_token; // Configure curl client and execute request $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $access_token_url); curl_setopt($ch, CURLOPT_POST, count($newrule)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($newrule)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'X-Shopify-Access-Token: '.$shops_token)); $result = curl_exec($ch); curl_close($ch); // Store the access token $result = json_decode($result, true); echo "<pre>"; print_r($result); }
Please let me know where I am doing mistake. I am getting following error while execute this curl.
Array ( [error] => 822: unexpected token at 'price_rule%5Btitle%5D=sadadsad&price_rule%5Btarget_type%5D=line_item&price_rule%5Btarget_selection%5D=all&price_rule%5Ballocation_method%5D=across&price_rule%5Bvalue_type%5D=fixed_amount&price_rule%5Bvalue%5D=-10.0&price_rule%5Bcustomer_selection%5D=all&price_rule%5Bstarts_at%5D=2017-01-19T17%3A59%3A10Z' )
Solved! Go to the solution
I think you will have much better success finding answers to PHP only related questions in places like StackOverflow. Error 822 is PHP, not API related. When I run the same request as a simple HTTP request through a client, it works just fine - so the problem's somewhere in the code and thus better served via StackOverflow IMO.
This is an accepted solution.
Yes I got where was the error, too late reply but thanks very much for your time and reply. we have to use only following herder in CURL request.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Shopify-Access-Token: '.$shops_token));
Awesome. Glad you have it working now!
I have an another problem with my Delete webhook, will you please check my following post?
https://community.shopify.com/c/Shopify-Apps/App-uninstall-Webhook-is-not-working-Laravel/m-p/478732
User | Count |
---|---|
16 | |
12 | |
7 | |
6 | |
5 |