Curl PATCH giving me an authentication error

For Workes & Pages, what is the name of the domain?

ricelandraider.win

What is the error number?

10000

What is the error message?

Authentication Error

What is the issue or error you’re encountering

I’m attempting to use a curl PATCH request to update my DNS records every time I open a new ngrok tunnel. However, no matter what I try, I’m getting an authentication error upon trying to run the script. I’ll paste the script in here once I figure out how to use this forum

Here’s my code. I was following an article, but have edited it a bit while troubleshooting.

#!/bin/bash
ngrok config add-authtoken <MY NGROK TOKEN>
ngrok tcp 25565 --log=stdout >/dev/null &
sleep 1
PUBLIC_URL=$(curl -sS http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')

IFS=":"
array=($PUBLIC_URL)
unset IFS;
PORT=${array[2]}
URL="${array[1]#??}"


curl -X PATCH "https://api.cloudflare.com/client/v4/zones/<ZONE ID>/dns_records/<RECORD ID>" \
  --header "X-Auth-Email: <My Account Email>" \
  --header "X-Auth-Key: <My Global API Key>" \
  -H "Content-Type: application/json" \
  -d '{
  "data": {
    "port": '$PORT',
    "target": "'$URL'"
  }
}'

Are you sure you’re using the global API key, and not a token you generated?

https://developers.cloudflare.com/fundamentals/api/get-started/keys/#view-your-global-api-key

I’m certain. I went to the “User API Tokens” page, and below the API tokens is the API keys, and I went to view the “Global API Key”, entered in my password, and accessed the key. I just now double checked to make sure the key inside my script is exactly the same as the one on the website.

Originally I was trying to use a token, but switched to using the global key to make sure I wouldn’t run into any issues with generating the wrong token given that I’m somewhat out of my depth when configuring the token

Ah, I finally spotted the mistake after triple and quadruple checking my keys for the umpteenth time-- I had accidentally pasted the record ID where the zone ID belongs.

1 Like

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