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

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" => "...",
        ...
    ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥15 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换