[英]Cloudflare API issue put request (“code”:9020,“message”:“Invalid DNS record type”)
I am having issue while using cloudflare APIv4. 使用cloudflare APIv4时出现问题。 Trying to update a dns record and not sure why am I receiving following error:
尝试更新DNS记录,但不确定为什么收到以下错误:
{"success":false,"errors":[{"code":1004,"message":"DNS Validation Error","error_chain":[{"code":9020,"message":"Invalid DNS record type"}]}],"messages":[],"result":null}
{“成功”:false,“错误”:[{“代码”:1004,“消息”:“ DNS验证错误”,“ error_chain”:[{“代码”:9020,“消息”:“无效的DNS记录类型“}]}],” 消息 “:[],” 结果“:空}
Here is the PHP function: 这是PHP函数:
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 另外,我按照Cloudflare API文档中的说明正确放置了记录类型“ A”
Could someone help me out with this issue? 有人可以帮我解决这个问题吗?
Thanks 谢谢
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: API的期望如下:
{"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: 这是您在PHP中正确构造JSON的方式:
$POST = json_encode(array(
"type" => "A",
"name" => "...",
...
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.