API Python Cheatsheet
API Python Cheatsheet
With the DNSimple library you can easily interact our powerful API to administer
domain names, configure DNS records, provision and install SSL certificates, and
more.
Getting Started
1. Install the Python library
2. Authenticate
3. Check Authorization
If you want to know which account is associated with the current access token, you can
use #identity . The account ID is required for the majority of API operations.
response = client.identity.whoami()
account = response.data.account
let account_id = accound.id;
Register A Domain
1. To register a domain, you need to specify a registrant_id. This can be fetched via
the Contacts API.
contacts = client.contacts.list_contacts(account_id).data
first_contact = contacts[0]
print(f'{first_contact.id}')
# => 123
# =>State: registered
# Auto Renew: false
# Whois Privacy: false
# Registrant: 123
DNS
# =>ID: 123
# Zone: foo.com
# Name: www
# Type: A
# Content: 137.0.0.1
Update a DNS record
Update a previously created DNS record.
input = ZoneRecordUpdateInput(ttl='60')
# =>ID: 123
# Updated TTL: 60
SSL Certificates
input = LetsencryptCertificateInput(
auto_renew=false,name='test-certificate')
certificate = client.certificates.purchase_letsencrypt_certificate(
account_id, 'foo.com', input)
# =>ID: 123
# State: new
Issue an Let's Encrypt Certificate
Issues the pending order. This process is async. A successful response means that the
response is queued.
issued = client.certificates.issue_letsencrypt_certificate(account_id,
'foo.com', certificate.id).data
print(f'State: {issued.state}')
# =>State: requesting
Install the certificate
Download the certificate.
certificate = client.certificates.download_certificate(account_id,
'foo.com', certificate.id).data
key = client.certificates.get_certificate_private_key(account_id,
'foo.com', certificate.id).data
file = open('www_foo_com.key')
file.write(key.private_key)
file.close