douye8500 2019-01-31 05:12
浏览 1179
已采纳

Cloudflare API问题放置请求(“代码”:9020,“消息”:“无效的DNS记录类型”)

I am having issue while using cloudflare APIv4. Trying to update a dns record and not sure why am I receiving following error:            

{"success":false,"errors":[{"code":1004,"message":"DNS Validation Error","error_chain":[{"code":9020,"message":"Invalid DNS record type"}]}],"messages":[],"result":null}

Here is the PHP function:          

function updateCloudflareDNS($zone_id,$dns_id, $updatedata){
 $updatedata = '[{"name":"**.****.com"},{"type":"A"},{"ttl":"1"},{"content":"8.8.8.8"},{"proxied":"true"}]';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/".$zone_id."/dns_records/".$dns_id);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json; charset=utf-8',
    'X-Auth-Email: **********',
    'X-Auth-Key: ***********'
));    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $updatedata);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    
$response = curl_exec($ch);
curl_close($ch);
return $response;
}

Also, I am putting record type "A" correctly as mentioned on the Cloudflare API documentation

Could someone help me out with this issue?

Thanks

  • 写回答

1条回答 默认 最新

  • drs3925 2019-01-31 06:46
    关注

    You're sending a payload of:

    [{"name":"**.****.com"},{"type":"A"},{"ttl":"1"},{"content":"8.8.8.8"},{"proxied":"true"}]

    Here's what the API expects:

    {"type":"A", "name":"example.com", "content":"127.0.0.1", "ttl":120, "priority":10,"proxied":false}

    And this is how you properly construct JSON in PHP:

    $POST = json_encode(array(
        "type" => "A",
        "name" => "...",
        ...
    ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?