Skip to content
Advertisement

Delete shopify price rule using curl php

I am trying to delete a price rule created through API. Create API works fine, but somehow delete is not working. Here is my code

$shop = "my-shopify-shop";
$token = "1321312312312321311";
$api_endpoint="/admin/api/2020-01/price_rules/#627965853827.json";
$url = "https://" . $shop . ".myshopify.com" . $api_endpoint;

$header=array('Content-Type: application/json','Authorization:Basic Og==','X-Shopify-Access-Token: ' .$token);

                $curl = curl_init();
                curl_setopt($curl, CURLOPT_URL, $url);
                curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_VERBOSE, 0);
                curl_setopt($curl, CURLOPT_HEADER, 1);
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST,"DELETE");
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                $response = curl_exec ($curl);
                if (curl_errno($curl)) {
                    die('Couldn't send request: ' . curl_error($curl));
                    } 
                curl_close ($curl);

                print_r($response);

And I’m getting output like this

enter image description here

What am I missing? Can anyone suggest?

Advertisement

Answer

Finally i got the solution,

I removed # before the rule id ,This was my endpoint

$api_endpoint="/admin/api/2020-01/price_rules/#627965853827.json";

But it should be

$api_endpoint="/admin/api/2020-01/price_rules/627965853827.json"; 

Hopes this would help somebody in future

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement