Skip to content

Commit

Permalink
Update record.py
Browse files Browse the repository at this point in the history
zone id get from os environment variable
  • Loading branch information
mftzk authored Jul 30, 2024
1 parent e1d0d64 commit 4002758
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions examples/dns/record.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import os
from cloudflare import Cloudflare


zone_id = os.getenv("CLOUDFLARE_ZONE_ID")
if zone_id is None:
sys.exit("CLOUDFLARE_ZONE_ID is not defined")

cloudflare_token = "your-cloudflare-token"
cloudflare_zone_id = "zone"
alias_name = "www.mydns.com"
cannonical_name = "cname.example.com"

client = Cloudflare()

client = Cloudflare()


# create dns using defined driver
record = client.dns.records.create(
zone_id=cloudflare_zone_id,
zone_id=zone_id,
type='CNAME',
name=alias_name,
content=cannonical_name,
proxied=False
)


# print output
print(record)
print(record)

1 comment on commit 4002758

@Phoenix591
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could query Cloudflare for the zone id from the name using zones.list, such as in this snippet from one of my scripts where I used cf as the client

            search = cf.zones.list(name=zone_name)
            zone_id = search.result[0].id

Please sign in to comment.