Successful API Call Still Doesn't Update Record

Hi. I wrote the following API call to update a DNS record:

> curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/<zoneid>/dns_records/<recordid>" \
>      -H "X-Auth-Email: <email>" \
>      -H "Authorization: Bearer <apikey>" \
>      -H "Content-Type: application/json" \
>      --data '{"type":"A","name":"<subdomain>.com","content":"'curl -s -X GET https://api.ipify.org'","ttl":1,"proxied":false}'

When I execute it on my laptop it updates the DNS record for , and it returns a response (copied below)

But when I execute it on the server, I get the same return (copied below), but it does not update the DNS record:

> {"result":{"id":"<recordid>","zone_id":"<zoneid>","zone_name":"[<domain>](http://<domain>.com)","name":"[<subdomain>.com](http://<subdomain>)","type":"A","content":"XXX.XXX.XXX.XXX","proxiable":false,"proxied":false,"ttl":1,"locked":false,"meta":{"auto_added":false,"managed_by_apps":false,"managed_by_argo_tunnel":false,"source":"primary"},"comment":null,"tags":[],"created_on":"2023-12-02T00:52:40.XXXXXXX","modified_on":"2023-12-02T17:54:22.XXXXXXXX"},"success":true,"errors":[],"messages":[]}

When I execute it onthe server I get no errors (I get the same return on both machines), but the DNS record does not update. Again, if I run the same command, and get the same reply on my laptop it does.

Sanity check: Is your server’s public IP different from your laptops?

Haha, yes. I set the DNS record to 192.168.1.1 for testing purposes before running the script on the server.

What if you separate the call to the IP address out of the actual address. Something like

IP=$(curl -s https://api.ipify.org)
curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/<zoneid>/dns_records/<recordid>" \
-H "X-Auth-Email: <email>" \
-H "Authorization: Bearer <apikey>" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"<subdomain>.com","content":"'"$IP"'","ttl":1,"proxied":false}'

(I think I got the quotes right on it)

Well, it’s a bash script, so I don’t know how to set variables like that, but I did go in and put the IP in manually and it updated the record. So that does have something to do with it. The mystery, I guess, is why it is returning a success code when it should be showing some kind of error.

Solved. Set the variable with this line:

ip=curl -silent -L http://checkip.amazonaws.com|tail -n 1

Then call it like this:

. . . --data ‘{“type”:“A”,“name”:“”,“content”:"’$ip’",“ttl”:1,“proxied”:false}’

1 Like

. . . apparently it was passing ‘null’ as the IP and for some reason that didn’t trigger the validity check in the return.

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