Adding multiple domains via the API

ExpertTip

#1

In the example below for adding multiple domains via the API, what is “id_of_that_account”? The email address associated with your Cloudflare account, or something different? I get “Malformed JSON in request body” errors using the email address.

for domain in $(cat domains.txt); do
curl -X POST -H “X-Auth-Key: $CF_API_KEY” -H “X-Auth-Email: $CF_API_EMAIL”
-H “Content-Type: application/json”
https://api.cloudflare.com/client/v4/zones
–data ‘{account: {“id: “id_of_that_account”}, name”:"’$domain’",“jump_start”:true}’; done


#2

Try this. It should return that ID.

https://api.cloudflare.com/#user-user-details


#3

That User ID might very well be the one in the URL when you go to dash.cloudflare.com


#4

Thanks! I bet it is the one in the dashboard URL.

Still getting that “Malformed JSON in request body” error, but that’s a different topic, I guess.


#5

Can confirm your first suggestion returns your user ID, and your second suggestion is the account ID.

Figured out the JSON error. There’re some mistakes in their example script.


#6

Hi, how have you been able to fix this issue?
I am also planning to add more domains. Regards and thanks


#7

In their example, this line:
–data ‘{account: {“id: “id_of_that_account”}, name”:"’$domain’",“jump_start”:true}’;
should be:
–data ‘{“account” : {“id” : “id_of_that_account”}, “name”:"’$domain’",“jump_start”:true}’;
It worked for me after that.


#8

Thanks, I am using it on Windows and I was not able to get the content from file “domains.txt” as it is not exactly same in Linux. But I am able to do it with a batch file currently, a bit longer as there is the full syntax for each name.