Purge Everything API is not working

I want to use the following API:

curl -X POST "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/purge_cache" \
     -H "X-Auth-Email: [email protected]" \
     -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
     -H "Content-Type: application/json" \
     --data '{"purge_everything":true}'

In my WordPress functions file I have triggered action and the above API has been called, but the result is as below:

{ "result": null, "success": false, "errors": [ { "code": 1012, "message": "Request must contain one of \"purge_everything\", \"files\", \"tags\", \"hosts\" or \"prefixes\"" } ], "messages": [] }

I am giving here my code for calling the API

 $endpoint = 'my_url';

$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $endpoint );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_HTTPHEADER, array(
            'X-Auth-Email: [email protected]',
            'X-Auth-Key: my_api_key',
            'Content-Type: application/json',
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, ["purge_everything"=>true] );
$result = curl_exec($curl);


The API is working, your request, respectively your code, isn’t.

As evident from the documentation, that call requires a JSON object in the request body, whereas you are sending a conventional POST request with form data.

This is not really a Cloudflare question, but rather a PHP one, hence I’d refer to the documentation of PHP or StackOverflow for more details on how to fix that.