Help with DNS API

Hello,
I was trying to use the API “List DNS Records”, after having activated my API token, which I verified it is valid and active with the curl GET “user/tokens/verify”.

Following the example in the API documentation, I have formatted the request in such a way:

curl -X GET “https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records
-H “Authorization: Bearer My_Token”
-H “Content-Type:application/json”

but I receive an authentication error in the following response:
{“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]}

Am I using maybe the wrong URI?

The token is configured with following permissions:
|Token name|Permissions|Resources|
|List_DNS_Records|Zone.DNS|All zones|

P.S. I have tried also with Auth_Key (API Key) but the result is the same…

Thank you for any advice you could give.
Rob

There doesn’t seem to be anything wrong with your request as shown above, except that it should all go in one line. I’ve copied/pasted, replaced with my API key (I didn’t bother creating a token for this) and it worked fine.

Make sure nothing is being lost or added when you copy keys and email to your curl request.

curl -X GET "https://api.cloudflare.com/client/v4/zones/$CF_Zone_ID/dns_records" -H "X-Auth-Email: $CF_Email" -H "X-Auth-Key: $CF_API_Key" -H "Content-Type: application/json"

Hello Floripare,
Thank you for feedback. There were backslashes at the end of each row to escape the EOL character and which have been hidden in the html view, maybe you can see them in the html source. The same format works with other requests.

Can you confirm that the EXA string of the DNS zone is correct? I tried to get the full list of identifiers stopping the url at /zones but I receive a strange output with details of my account instead of the full list of zones.

Maybe I forgot anything in token activation?
Thanks again!

Roberto Trama

1 Like

FYI you can always wrap content in backticks or use the code icon to make them show as intended in the community forum.
image

I cannot. You should open your Cloudflare dashboard and select the relevant zone, then copy the Zone ID from there using their “click to copy” tool to avoid adding return carriage and other possible invisible characters.
image

Cloudflare API always returns in JSON format, and it’s up to user to parse it. Returns are also often very verbose, so you need to skim through to pick the specific data you need, or else familiarize yourself with jq and other command line tools to help you in the process.

2 Likes

Hello,
thank you very much! I have been able to retrieve the list of DNS record as planned.
I suspected I was using the wrong zone id, but did not know where to take the correct one. Thanks again!

1 Like

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