Table of Contents
- Class:
HetznerDnsClientnew HetznerDnsClient(token, [baseUrl])hetznerDnsClient.zoneshetznerDnsClient.zones.getAll([options])hetznerDnsClient.zones.create(name, [ttl])hetznerDnsClient.zones.get(id)hetznerDnsClient.zones.update(id, name, [ttl])hetznerDnsClient.zones.delete(id)hetznerDnsClient.zones.importZone(id, file)hetznerDnsClient.zones.exportZone(id)hetznerDnsClient.zones.validateZone(file)
hetznerDnsClient.recordshetznerDnsClient.records.getAll([zoneId])hetznerDnsClient.records.create(zoneId, name, type, value, [ttl])hetznerDnsClient.records.get(id)hetznerDnsClient.records.update(id, zoneId, name, type, value, [ttl])hetznerDnsClient.records.delete(id)hetznerDnsClient.records.bulkCreate(records)hetznerDnsClient.records.bulkUpdate(records)
hetznerDnsClient.primaryServers
- Class:
Zone - Class:
DnsRecord - Class:
PrimaryServer - Class:
ApiResponse<T extends ErrorModel> - Class:
Zones - Class:
ClientObject<T> - Class:
BulkCreateRecordsPretty - Class:
BulkUpdateRecordsPretty - Class:
ZoneValidationPretty - Class:
ApiError - Class:
ClientParseError - Interface:
ErrorModel - Interface:
ZoneModel - Interface:
BulkCreateRecords - Interface:
BulkUpdateRecords - Interface:
BaseRecordModel - Interface:
RecordModel - Interface:
PrimaryServerModel - Interface:
PaginatedZones - Interface:
PaginatedData - Interface:
ZoneValidation
Hetzner DNS API client for Node.js
Create a new Hetzner DNS API client
tokenstringHetzner DNS API token/keybaseUrlURL | undefinedBase URL for the API (default:https://dns.hetzner.com/api/v1)
A secondary zone can be created, by adding a primary server before adding any records.
Get all Zones
optionsObjectSearch optionsoptions.namestring | undefinedFull name of a zone. Will return an array with one or no results. Example:example.comoptions.pagenumber | undefinedA page parameter specifies the page to fetch. The number of the first page is 1. Must be >= 1.options.perPagenumber | undefinedNumber of zones to be shown per page. Returns 100 by default. Maximum 100.options.searchNamestring | undefinedPartial name of a zone. Will return an array with zones that contain the searched string. Example:example
- Returns:
Promise<Zones> - Throws:
ApiError,ClientParseError
Create Zone
namestringSeezone.namettlnumber | undefinedSeezone.ttl- Returns:
Promise<Zone> - Throws:
ApiError,ClientParseError
Get Zone
idstringID of zone to get- Returns:
Promise<Zone> - Throws:
ApiError,ClientParseError
Update Zone
idstringID of zone to updatenamestringThe current name of the zone. Changing zone name is not possible.ttlnumber | undefinedNew TTL for the zone (seezone.ttl)- Returns:
Promise<Zone> - Throws:
ApiError,ClientParseError
Delete Zone
Import Zone file plain
idstringID of zone to import tofilestring | Uint8Array | Buffer | readonly number[]Zone file contents to import- Returns:
Promise<Zone> - Throws:
ApiError,ClientParseError
Export Zone file
Validate Zone file plain
Warning: As of Jan 19, 2023, this endpoint appears to always return an empty array for valid records.
filestring | Uint8Array | Buffer | readonly number[]Zone file contents to validate- Returns:
Promise<ZoneValidationPretty> - Throws:
ApiError,ClientParseError
Get All Records
zoneIdstringID of zone to get records of- Returns:
Promise<DnsRecord[]> - Throws:
ApiError,ClientParseError
Create Record
zoneIdstringID of zone to create record innamestringSeednsRecord.nametypeDnsRecord.TypeSeednsRecord.typevaluestringSeednsRecord.valuettlnumber | undefinedSeednsRecord.ttl- Returns:
Promise<DnsRecord> - Throws:
ApiError,ClientParseError
Get Record
idstringID of record to get- Returns:
Promise<DnsRecord> - Throws:
ApiError,ClientParseError
Update Record
idstringID of record to updatezoneIdstringID of zone the record is associated with. Note: Changing the zone of a record is not possible.typeDnsRecord.TypeSeednsRecord.type. Note: Changing the type of a record is not possible.namestringSeednsRecord.namevaluestringSeednsRecord.valuettlnumber | undefinedSeednsRecord.ttl- Returns:
Promise<DnsRecord> - Throws:
ApiError,ClientParseError
Delete Record
Bulk Create Records
recordsObject[]Array of records to createrecords[].namestringSeednsRecord.namerecords[].ttlnumber | undefinedSeednsRecord.ttlrecords[].typeDnsRecord.TypeSeednsRecord.typerecords[].valuestringSeednsRecord.valuerecords[].zoneIdstringID of zone to create the record in
- Returns:
Promise<BulkCreateRecordsPretty> - Throws:
ApiError,ClientParseError
Bulk Update Records
recordsObject[]Array of records to updaterecords[].idstringID of record to updaterecords[].namestringSeednsRecord.namerecords[].ttlnumber | undefinedSeednsRecord.ttlrecords[].typeDnsRecord.TypeSeednsRecord.type. Note: Changing the type of a record is not possible.records[].valuestringSeednsRecord.valuerecords[].zoneIdstringID of zone the record is associated with. Note: Changing the zone of a record is not possible.
- Returns:
Promise<BulkUpdateRecordsPretty> - Throws:
ApiError,ClientParseError
Primary servers can only be added to a zone, if no records were added to it, yet. By adding a primary server to a newly created zone, it automatically becomes a secondary zone.
Get All Primary Servers
zoneIdstring | undefinedID of zone to get primary servers for- Returns:
Promise<PrimaryServer[]> - Throws:
ApiError,ClientParseError
Create Primary Server
zoneIdstringID of zone to create the primary server inaddressstringSeeprimaryServer.addressportnumberSeeprimaryServer.port- Returns:
Promise<PrimaryServer> - Throws:
ApiError,ClientParseError
Get Primary Server
idstringID of primary server to get- Returns:
Promise<PrimaryServer> - Throws:
ApiError,ClientParseError
Update Primary Server
idstringID of primary server to updatezoneIdstringID of zone the primary server is associated with. Note: Changing the zone of a primary server is not possible.addressstringSeeprimaryServer.addressportnumberSeeprimaryServer.port- Returns:
Promise<PrimaryServer> - Throws:
ApiError,ClientParseError
Delete Primary Server
Hetzner DNS Zone
- Extends:
ClientObject<ZoneModel>
Zone ID
- Type:
string - Read only
Zone name (i.e. domain name)
- Type:
string - Read only
Zone creation time
- Type:
Date - Read only
Zone modification time
- Type:
Date - Read only
Zone default TTL (time to live) in seconds
- Type:
number - Read only
Whether this is a secondary zone Secondary zones have primary servers (see zone.getPrimaryServers()) instead of records (see zone.getRecords())
- Type:
boolean - Read only
The number of records in this zone
- Type:
number - Read only
Change zone default TTL (time to live)
ttlnumberNew zone default TTL- Returns:
Promise<Zone>The updated zone object. Note: Avoid using the old object after updating it to avoid inconsistencies. You should use the new zone object returned by this method. - Throws:
ApiError,ClientParseError
Import records from a zone file
filestring | Uint8Array | Buffer | readonly number[]Zone file contents- Returns:
Promise<Zone>The updated zone object. Note: Avoid using the old object after updating it to avoid inconsistencies. You should use the new zone object returned by this method. - Throws:
ApiError,ClientParseError
Export zone file
Delete this zone
Get all records in this zone
- Returns:
Promise<DnsRecord[]> - Throws:
ApiError,ClientParseError
Get all primary servers for this zone
- Returns:
Promise<PrimaryServer[]> - Throws:
ApiError,ClientParseError
Create a new record in this zone
namestringSeednsRecord.nametypeDnsRecord.TypeSeednsRecord.typevaluestringSeednsRecord.valuettlnumber | undefinedSeednsRecord.ttl- Returns:
Promise<DnsRecord>The created record object - Throws:
ApiError,ClientParseError
Create a primary server for this zone
addressstringSeeprimaryServer.addressportnumberSeeprimaryServer.port- Returns:
Promise<PrimaryServer>The created primary server object - Throws:
ApiError,ClientParseError
Hetzner DNS Record
- Extends:
ClientObject<RecordModel>
Type of record
AA records are the most commonly used type of record. They simply point your hostname to an IPv4 address.AAAAAAAA (quad-A) records are similar to A records, but they point your hostname to an IPv6 address instead of an IPv4 address.PTRPTR records are used to map an IP address to a hostname. They are commonly used for reverse DNS lookups.NSNS records determine which name servers are authoritative to the domain (or subdomain). They are typically used together with A records. Several NS records may be associated with a single zone at once.MXMX records handle the exchange of e-mails, and are used specifically for mail servers.Attention: In the “Value” field, remember to put a dot . at the end of the hostname reference if you need one.
CNAMECNAME records point your hostname to another domain. IP addresses are not accepted, as these will be handled by the records of the target domain. CNAME records cannot be added to a zone if there are any other existing records with the same name, regardless of type.Attention: In the “Value” field, remember to put a dot . at the end of the hostname reference if you need one.
RPInformation about the responsible person(s) for the domain. Usually an email address with the @ replaced by a .TXTTXT records are plain text records that contain general information about your domain. A TXT record may often follow a certain specification (e.g. DKIM, DMARC) depending on its purpose.SOASpecifies authoritative information about a DNS zone, including the primary name server, the email of the domain administrator, the domain serial number, and several timers relating to refreshing the zone.Note: Creating SOA records is not supported by the API.
HINFORecord intended to provide information about host CPU type and operating system. It was intended to allow protocols to optimize processing when communicating with similar peers.SRVSRV records are used to specify server locations and their specified services.DANENote: Creating DANE records is not supported by the API.
TLSAA record for DANE. RFC 6698 defines “The TLSA DNS resource record is used to associate a TLS server certificate or public key with the domain name where the record is found, thus forming a 'TLSA certificate association'“.DSThe record used to identify the DNSSEC signing key of a delegated zone.CAACAA Records allow you to specify which Certification Authorities can issue a certificate for your zone.
Get the record type from string
typestringRecord type string- Returns:
DnsRecord.Type | nullRecord type enum value or null if not found
Record ID
- Type:
string - Read only
Record name
- Type:
string - Read only
Record type
- Type:
DnsRecord.Type - Read only
Record value
- Type:
string - Read only
Record TTL (time to live) in seconds
Null if not set (i.e. depends on the zone default)
Time record was created
- Type:
Date - Read only
Time record was last updated
- Type:
Date - Read only
Zone ID this record is associated with
- Type:
string - Read only
Get the zone object this record belongs to
- Returns:
Promise<Zone>Promise that resolves to the zone object - Throws:
ApiError,ClientParseError
Update the record
optionsObjectUpdate options- Returns:
Promise<DnsRecord> - Throws:
ApiError,ClientParseError
Delete the record
Primary server
- Extends:
ClientObject<PrimaryServerModel>
ID of the primary server
- Type:
string - Read only
IPv4 or IPv6 address of the primary server
- Type:
string - Read only
Port number of the primary server (from 1 to 65535)
- Type:
number - Read only
ID of zone this primary server is associated with
- Type:
string - Read only
Time primary server was created
- Type:
Date - Read only
Time primary server was last updated
- Type:
Date - Read only
Get zone this primary server is associated with
- Returns:
Promise<Zone>Promise that resolves to the zone object - Throws:
ApiError,ClientParseError
Update primary server
optionsObjectUpdate optionsoptions.addressstring | undefinedNew server address (seeprimaryServer.address)options.portnumber | undefinedNew server port (seeprimaryServer.port)
- Returns:
Promise<PrimaryServer>The updated primary server object. Note: Avoid using the old object after updating it to avoid inconsistencies. You should use the new primary server object returned by this method. - Throws:
ApiError,ClientParseError
Delete this primary server
API response object
- Template:
TErrorModelResponse data model
Fetch response
- Type:
Response - Read only
Raw response body
- Type:
ArrayBuffer - Read only
Request options
- Type:
RequestInit - Read only
API client instance used to make the request
- Type:
HetznerDnsClient - Read only
Get response body as string
- Type:
string - Read only
Get parsed response body (if JSON). null if not JSON or parsing fails.
- Type:
T | null - Read only
A collection of zones
- Extends:
ClientObject<PaginatedZones>
Get zones in this collection
- Type:
Zone[] - Read only
Get number of zones in this collection
- Type:
number - Read only
Check if this is the last page
- Type:
boolean - Read only
Whether this collection contains all possible zones from the time of fetching.
- Type:
boolean - Read only
Fetch next page of zones and attach them to this collection
- Returns:
Promise<Zones | null>The newly fetched page or null if there are no more pages - Throws:
ApiError,ClientParseError
Fetch all pages after the current page and attach them to this collection.
Note: This method will make multiple API calls and may take a while, depending on the number of zones.
- Returns:
Promise<void> - Throws:
ApiError,ClientParseError
Client object
- Template:
TRaw data model
API client instance
- Type:
HetznerDnsClient - Read only
Raw data
- Type:
T - Read only
Response from bulk creating records
- Extends:
ClientObject<BulkCreateRecords>
Invalid records
- Type:
BaseRecordModel[] - Read only
Records that were created
- Type:
DnsRecord[] - Read only
Valid records
- Type:
BaseRecordModel[] - Read only
Response from bulk updating records
- Extends:
ClientObject<BulkUpdateRecords>
Failed records
- Type:
BaseRecordModel[] - Read only
Records that were updated
- Type:
DnsRecord[] - Read only
Hetzner DNS Zone Validation
- Extends:
ClientObject<ZoneValidation>
Number of parsed records
- Type:
number - Read only
Valid records
- Type:
DnsRecord[] - Read only
Hetzner API error
- Extends:
Error
Standard messages returned by the API i.e. messages returned with a standard error JSON response
Non-standard error messages
Sometimes the Hetzner API returns non-JSON responses, or e.g. it issues a redirect to the login page when credentials are invalid
Name of the error
- Type:
"ApiError" - Read only
- Override
Error code
- Type:
number - Read only
Full API response
- Type:
ApiResponse<any> - Read only
API client failed to understand and parse the API response
- Extends:
Error
Name of the error
- Type:
"ClientParseError" - Read only
- Type:
"API client failed to understand and parse the API response" - Read only
Error model of API responses
Hetzner DNS zone model
idstringUnique identifier of the zonecreatedstringZone creation timestamp in ISO 8601 formatmodifiedstringTimestamp of the last change of the zone in ISO 8601 formatlegacy_dns_hoststringLegacy DNS host name of the zonelegacy_nsstring[]Legacy name server names of the zonenamestringName of the zonensstring[]Name server names of the zoneownerstringZone ownerpausedbooleanWhether the zone is pausedpermissionstringPermission of the zoneprojectstringProject of the zoneregistrarstringZone registrarstatus"verified"Status of the zonettlnumberDefault TTL (time to live) in seconds for records in this DNS zoneverifiedstringZone verification timestamp in ISO 8601 format or empty stringrecords_countnumberNumber of records in the zonetxt_verificationObjectTXT record verificationis_secondary_dnsbooleanWhether this is a secondary zone
Bulk create records API response model
- Extends:
ErrorModel invalid_recordsBaseRecordModel[]recordsRecordModel[]valid_recordsBaseRecordModel[]
Bulk update records response model
- Extends:
ErrorModel failed_recordsBaseRecordModel[]recordsRecordModel[]
Base record model
namestringName of recordttlnumber | undefinedTime to live in secondstypestringType of record (string corresponding to enum value fromDnsRecord.Type)valuestringValue of recordzone_idstringID of zone this record is associated with
Record model
- Extends:
BaseRecordModel createdstringTime record was created (ISO 8601)idstringID of recordmodifiedstringTime record was last updated (ISO 8601)
Primary server model
idstringPrimary server IDaddressstringIPv4 or IPv6 address of the primary serverportnumberPort number of the primary server (from 1 to 65535)zone_idstringID of zone this primary server is associated withcreated_atstringTime primary server was created (ISO 8601)updated_atstringTime primary server was last updated (ISO 8601)
API response with paginated zones
- Extends:
PaginatedData zonesZoneModel[]List of zones
Paginated API response
- Extends:
ErrorModel metaObjectResponse metadata
Zone file validation response
- Extends:
ErrorModel parsed_recordsnumberNumber of parsed recordsvalid_recordsRecordModel[]Valid records