To create a zone through the API you need an account ID. But to get an account ID you need to create a zone. Feels like the chicken or the egg dilemma.
How to get my account ID to create a zone if there are no existing zones yet? Preferably, I want to get the account ID through an API call instead of looking it up somewhere on the dashboard.
Bonus question: Can you have multiple account ID’s? If so, how?
The global API key should be under your profile settings…
The API key is used to authenticate with the API so you can’t get your API key from the API.
As API global keys give full access, API use is best done programmatically by creating tokens with only the permissions needed.
I don’t use the global API and I am not looking for this key. I already have an API token and now I am looking for the account ID that is required for Zones Post command.
Ask the API for the account list…
I have seen that command but it does not list any account. It also does not include an ID according to the documentation so it does not seem to be the account ID that is usually listed in the zone information.
Works for me…
url --request GET \
--url https://api.cloudflare.com/client/v4/accounts \
--header 'Content-Type: application/json' \
--header 'X-Auth-Email: xxxxxxxxxx \
--header 'X-Auth-Key: xxxxxxxxx'
Or you can get just it from the dashboard URL in the browser…
Thank you! I now see that it was a permission issue with the API token. You need to have Account Settings enabled to get a good result for that call.
Too bad Cloudflare does not show a permission warning with this call to notice that you do not have the right permissions.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.