[QUESTION] How am I supposed to enter account name in script?
mlazzarotto opened this issue · 5 comments
Let's say that I have an account registered with email 'Bill.gates@microsoft.com'.
What should I put as parameter when using cf.zones.get
?
I tried different combinations but only if I provide my account ID I'm able to retrieve the zone list.
This is what I expect to work:
def main():
cf = CloudFlare.CloudFlare(profile='Cloudflare')
zones = cf.zones.get(
params={'per_page': 200,
'name': 'Bill.gates@microsoft.com'})
for zone in zones:
zone_name = zone['name']
zone_id = zone['id']
print("id={} - name={}".format(zone_id, zone_name))
If your issues (it's unclear) is to do with authentication:
Within the README file visible at https://github.com/cloudflare/python-cloudflare/ you'll see where to add your email & token for authentication purposes (your config file or via environment variables).
If your issues is to do with having more than one account associated with your email address, then in your param's variable you can add ...
'account.name': 'the-account-name',
... you only add arguments to your Cloudflare calls IF there are arguments within the API listing. See https://api.cloudflare.com/ for full listing if calls.
Please also scan the examples folder for help.
Does that answer your question?
Yes, by using account it is working now, but anyway on https://api.cloudflare.com/#zone-list-zones I don't see any reference to account while I see reference to account.id.
Is the documentation wrong maybe?
Sorry, there was a typo (now corrected) in my first account ... I was typing too fast! :) It's ...
'account.name': 'the-account-name',
You can test all this with the command line cli4
program. For example ...
$ cli4 account.name="THE-ACCOUNT-NAME" /zones | jq -c ".[]|.id,.name" | paste - -
"00000000000000000000000000000000" "example.com"
"00000000000000000000000000000000" "example.net"
$
You were correct in your read of https://api.cloudflare.com/#zone-list-zones and I was wrong with the param account
. The documentation is correct and its account.name
(or account.id
if you already know the 32 digit account number already.
Hope that gets you back on track (and don't forget that you can test quickly with cli4
.
Sorry, there was a typo (now corrected) in my first account ... I was typing too fast! :) It's ...
No! You were right and the documentation is wrong!
This works
cf = CloudFlare.CloudFlare(profile='Cloudflare')
zones = cf.zones.get(
params={'per_page': 200,
'account': "system.admins@abc.net's Account"})
this doesn't
cf = CloudFlare.CloudFlare(profile='Cloudflare')
zones = cf.zones.get(
params={'per_page': 200,
'account.name': "system.admins@abc.net's Account"})
FYI: If you use the https://dash.cloudflare.com/ site, you can change your account name so it's a simpler string.
Your example above is beyond the Python library; however, any param passed that is not part of the API is ignored. The following shows that. This is valid:
$ cli4 account.name="ONE-OF-MY-ACCOUNTS" /zones | jq -c ".[]|.id,.name" | paste - - | wc -l
4
$
This is ignored (and all my zones from all my accounts are shown):
$ cli4 accountwhatever="xyz" per_page=1000 /zones | jq -c ".[]|.id,.name" | paste - -
131
$
Hence I think the issue is the exact spelling (and/or) character encoding of your account name (that's why I recommend changing it via the dashboard (or even via the API). Oh ... run this command:
$ cli4 /accounts | jq -c ".[]|.id,.name" | paste - -
"00000000000000000000000000000000" "Martin Levy"
"00000000000000000000000000000000" "XXXXX"
"00000000000000000000000000000000" "YYYYYYYYYYY"
"00000000000000000000000000000000" "ZZZ"
$
Hope that helps.