Domain API FAQ

How-to search and list your domains

Paging results:

>>> api.domain.list(apikey, {'items_per_page': 10, 'page': 0})

Sorting results:

>>> api.domain.list(apikey, {'sort_by' : 'date_registry_end desc'})

Available search filters include:

  • fqdn
  • status
  • tld
  • owner

The full list of filters can be found in the domain.list() method documentation.

Listing all domains with a FQDN like ‘%mydomain%’:

>>> api.domain.list(apikey, {'~fqdn': '%mydomain%'})

Listing all domains with ‘FLN123-GANDI’ as owner:

>>> api.domain.list(apikey, {'owner': 'FLN123-GANDI'})

Listing all domains with an expiration date after a given date:

>>> api.domain.list(apikey, {'>date_registry_end' : '2011-01-01 00:00:00'})

Listing domains by TLD:

>>> api.domain.list(apikey, {'tld' : 'fr'})

Listing domains by status:

>>> api.domain.list(apikey, {'status' : 'clientTransferProhibited'})

All together:

>>> api.domain.list(apikey, {
  'items_per_page': 10,
  'sort_by' : 'date_registry_end desc',
  'page': 1,
  '~fqdn': '%mydomain%',
  'owner': 'FLN123-GANDI',
  'status' : 'clientTransferProhibited',
  '>date_registry_end' : '2011-01-01 00:00:00'
  })

How to manage your zones

List the zones you have access to

This include:

  • Gandi “public”, default zones
  • Zones from domains you have a “tech” access
  • Zones you’ve created
>>> zones = api.domain.zone.list(apikey)
>>> zones
[{'id': 1,
  'name': 'Gandi Zone',
  'version': 1},
  'date_updated': datetime.datetime(2007, 1, 10, 21, 1, 12),
 {'id': 115553,
  'name': 'Gandi Zone 2007',
  'version': 1},
  'date_updated': datetime.datetime(2007, 6, 19, 9, 57, 14),
 {'id': 151377,
  'name': 'Custom zone XY',}
  'version': 2},
  'date_updated': datetime.datetime(2010, 12, 19, 9, 50, 47),
]

Note

you can only modify the zones you own

Duplicate an existing zone

Create a new zone, copy an existing one:

>>> newzone = api.domain.zone.clone(apikey, 115553)
>>> newzone
{'id': 321460,
 'domains': 0,
 'name': 'Gandi Zone 2007 (1)',
 'owner': 'FLN123-GANDI',
 'version': 1,
 'versions': [1],
 'date_updated': datetime.datetime(2012, 1, 11, 15, 38, 58)}

List zone contents

You’ll have to provide this method with the version of the zone, or 0 for the active version:

>>> records = api.domain.zone.record.list(apikey, 321461, 0)
>>> records
[{'id': 16493531,
  'name': 'www',
  'ttl': 10800,
  'type': 'CNAME',
  'value': 'webredir.vip.gandi.net.'},
 {'id': 16493532,
  'name': '@',
  'ttl': 10800,
  'type': 'A',
  'value': '217.70.184.38'},
 {'id': 16493533,
  'name': '@',
  'ttl': 10800,
  'type': 'MX',
  'value': '10 spool.mail.gandi.net.'},
 # …
]

Replace some records

Note

you’ll need to create a new version before editing a zone

You can delete records with the same filters as the lists (don’t forget the filter ^^)

And add records individually with the add method:

>>> zone_id = 321461
>>> version = api.domain.zone.version.new(apikey, zone_id)
>>> version
2
>>> # Number of deleted records
>>> api.domain.zone.record.delete(apikey, zone_id, version,
...     { "type" : [ "A", "CNAME"], "name" : [ "@", "www"] })
2
>>> api.domain.zone.record.add(apikey, zone_id, version,
... { "type" : "A", "name": "@", "value": "192.168.1.10" })
{"id": 16493560,
 'ttl': 10800,
 'type': 'A',
 'name': '@',
 'value': '192.168.1.10'}
>>> api.domain.zone.record.add(apikey, zone_id, version,
... { "type" : "CNAME", "name": "www",
...   "value": "www7.myself.net.", "ttl": 3600})

{'id': 16493561,
 'ttl': 3600,
 'type': 'CNAME',
 'name': 'www',
 'value': 'www7.myself.net.'}

Replace the whole zone

You can also overwrite the whole zone in one call with the records you wish to add.

You can use a list of structures, or a single string representing the zone:

>>> zone_id = 321461
>>> version = api.domain.zone.version.new(apikey, zone_id)
>>> version
3
>>> records = api.domain.zone.record.set(apikey, zone_id, version,
[
  { "type" : "A", "name": "@", "value": "192.168.1.10" },
  { "type" : "CNAME", "name" : "www", "value" : "x.mine.net." },
  { "type" : "CNAME", "name" : "www2", "value" : "www" },
  { "type" : "MX", "name" : "@", "value" : "10 relay.mail.mx.", "ttl" : 604800},
])
>>> records
[
 {'ttl': 10800, 'type': 'A', 'name': '@', 'value': '192.168.1.10', 'id': 16493582},
 {'ttl': 10800, 'type': 'CNAME', 'name': 'www', 'value': 'x.mine.net.', 'id': 16493583},
 {'ttl': 10800, 'type': 'CNAME', 'name': 'www2', 'value': 'www', 'id': 16493584},
 {'ttl': 604800, 'type': 'MX', 'name': '@', 'value': '10 relay.mail.mx.', 'id': 16493585}
]
# Single string
>>> records = api.domain.zone.record.set(apikey, zone_id, version,
... """
... @            IN A     192.168.1.10
... www          IN CNAME x.mine.net.
... www2         IN CNAME www
... @     604800 IN MX    10 relay.mail.mx.
... """)
>>> records
[
 {'ttl': 10800, 'type': 'A', 'name': '@', 'value': '192.168.1.10', 'id': 16493582},
 {'ttl': 10800, 'type': 'CNAME', 'name': 'www', 'value': 'x.mine.net.', 'id': 16493583},
 {'ttl': 10800, 'type': 'CNAME', 'name': 'www2', 'value': 'www', 'id': 16493584},
 {'ttl': 604800, 'type': 'MX', 'name': '@', 'value': '10 relay.mail.mx.', 'id': 16493585}
]

DNSSEC

Add a public key to a domain

You need to provide the information related to your DNSKEY record: flags / algorithm / public key

  • flags is 256/257 (ZSK/KSK) – you should probably only push your KSK
  • algorithm is your keys’salgorithm
  • public_key is the base64 representation of your public key
>>> op = api.domain.dnssec.create(apikey, "b4c6.fr", {
... "flags": 257,
... "algorithm": 5,
... "public_key": "AwEAAdYixYvq9eJLRQcxUeYJWaxAGXiP/K1/C7XHbUWGzA8AHCRp81FA" \
...   "mfwcw1FrJ7bMViEegewPDGciQSv5HotPPOynUmkZbgztOeejH/+3Il/c" \
...   "M8SW4Et0i+99S7l9as+FI3AYOhsllDJK1WM9smn0S/9igfpR2dGmCyDU ZfeR1A49"})

This create an operation that will add the key at registry. The keytag and hash are automatically generated.

Note

some registries restrict the algorithms you may use, in that case the operation will end up in ERROR

Note

there is currently a bug/limitation that prevents multiple technical operations on a single domain for AFNIC domains. While an add operation is still running, subsequent operations will probably fail.

List a domain’s keys

Since we currently limit keys to 4 per domain, no list options here, only the full list.

Note that keys are only present here after they are successfully created at registry.

>>> keys = api.domain.dnssec.list(apikey, "b4c6.fr")
>>> keys
[{'algorithm': 5,
  'date_created': datetime.datetime(2012, 2, 24, 17, 16, 8),
  'digest': '457c626c008cc70d68133254abc4ee4eb79e4e6c99f9423b60b543fa8a69e6ac',
  'digest_type': 2,
  'flags': 257,
  'id': 125,
  'keytag': 9301,
  'public_key': 'AwEAAdYixYvq9eJLRQcxUeYJWaxAGXiP/K1/C7XHbUWGzA8AHCRp81FA' \
    'mfwcw1FrJ7bMViEegewPDGciQSv5HotPPOynUmkZbgztOeejH/+3Il/c' \
    'M8SW4Et0i+99S7l9as+FI3AYOhsllDJK1WM9smn0S/9igfpR2dGmCyDU ZfeR1A49\n'}]

Note

in some cases, some of these fields may be nil. When keys are imported from registry after a transfer for example.

Remove a key from its domain

This is done using the key id:

>>> op = api.domain.dnssec.delete(apikey, 125)