API to update DNS record not respecting 'name'?

I’m currently trying to write a PowerShell script (though this question is agnostic to my REST client / scripting language), so that I can regularly update a single A record (non-proxied).

Everything works just as expected, except that the ‘name’ property is changed from $hostname to the root of the zone after the IP updates (which is side-by-side with another A record of the same name that points somewhere else and IS proxied).

So e.g. if $hostname is set to “foo .bar .com”, even though the A record at $dnsRecordID is already set to “foo .bar .com”, this script changes it to “bar .com” (in addition to correctly setting the IP).

I get the same behavior if I set $hostname to just “foo” as well.

$body = ConvertTo-Json @{
‘type’ = ‘A’
‘name’ = $hostname
‘content’ = $myIP
‘ttl’ = 1

Write-Output “Attempting to update $hostname in zone ID $ZoneID and DNS Record ID $dnsRecordID with IP $myIP”

Invoke-RestMethod https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records/$dnsRecordID -Method Put -Authentication Bearer -Token $token -Body $body

Extend your Write-Output call to include $body as well and post the output here (make sure you redact any authentication details).

So essentially you are saying the call succeeds but it doesnt set the desired hostname but updates the naked domain instead? Have you already tried hardcoding “foo” as value for “name”? Whats the return value of Invoke-RestMethod?

Good call…it looks like my naive conversion from a hashtable to JSON is passing a whole bunch of ■■■■ that’s definitely not expected on the server side. Whoops.

Thanks for the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.