php - Error when requesting an API Cloudflare. Why?

722

when I am run the following code:

<?php
$name = $_POST ["name"]; // its ZoneID
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/zones/$name/settings/ipv6');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');

curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"value\":\"off\"}");

$headers = array();
$headers[] = 'X-Auth-Email: MAIL';
$headers[] = 'X-Auth-Key: TOKEN';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

var_dump($result);

curl_close($ch);
?>

I get in response:

"{“success”:false,“errors”:[{“code”:7000,“message”:“No route for that URI”}],“messages”:[],“result”:null}"

$name I need to get from the form

Where is my mistake ?

People are also looking for solutions to the problem: php - Laravel back() or redirect() does not work in Traits

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.