Cloudflare API 发出放置请求 ("code":9020,"message":"Invalid DNS record type")

Cloudflare API issue put request ("code":9020,"message":"Invalid DNS record type")

我在使用 cloudflare APIv4 时遇到问题。尝试更新 DNS 记录但不确定为什么会收到以下错误:

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

这是 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;
}

此外,我按照 Cloudflare API documentation

中提到的正确输入记录类型 "A"

有人可以帮我解决这个问题吗?

谢谢

您发送的负载为:

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

这是 API 的预期:

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

这就是您在 PHP 中正确构造 JSON 的方式:

$POST = json_encode(array(
    "type" => "A",
    "name" => "...",
    ...
));