PHP post failed cloudflare api

Viewed 36

i'm trying to update my DNS domain record through cloudflare api using PHP Post, but the cloudflare api send response that POST method is not allowed for the api_token authentication scheme, i already tried the the api using postman and it works, but somehow in PHP the api does not work, is PHP does not support POST using token ?, some variable is stored inside env.php and i hide it because it sensitive information.

PHP code :

    include("../../env.php");

    //variable input by POST
    $domain = $_POST['domain'];
    $recordID = $_POST['recordID'];
    $content = $_POST['content'];
    $zoneID = $_POST['zoneID'];

    //for update record
    $linkRecord = "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records/$recordID";
  
    $header = array(
        "Content-Type: application/json",
        "Authorization: Bearer $authToken"
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $linkRecord);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

    $bodyArray = array("type"=>"A","name"=>$domain,"content"=>$content,"proxied"=>true);

    $body = json_encode($bodyArray);


    curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
    $resp = curl_exec($curl);

    print_r($resp);

linkRecord Variable Value:

https://api.cloudflare.com/client/v4/zones/{{my_secret_zone_id}}/dns_records/{{id_of_the_record}}

Cloudflare response of POST :

{
  "success": false,
  "errors": [
    {
      "code": 10000,
      "message": "POST method not allowed for the api_token authentication scheme"
    }
  ]
}
0 Answers
Related