Registrar API

How a billing system (a platform that sells domain names) uses Salt to find out what a name costs, register it, renew it and manage it. Salt holds the registrar account and its credentials; the billing system never sees them. It sees a token, references it chooses, and money as whole numbers. The OpenAPI document (/api/v1/openapi.json) has every field. The module and how it works inside are in registrar.md.

The registrar API exists only while SALT_DNS_REGISTRAR=on; otherwise every route below answers 404.

1. The token and its level

A token's access to the registrar is its own setting, the registrar level, and zone grants do not count:

LevelMay do
none (the default)nothing: every registrar call is 403
readaccount, check, prices, list and read domains, read operations
purchaseeverything, including the calls that spend money

An owner or admin sets the level when they create a token in the console (Credentials for an ordinary token, Provisioning for a provisioning token) and can change it there later. From the command line, a provisioning token with a level:

bin/salt_dns eval 'IO.puts(SaltDns.Release.create_provisioning_token(1, "me@example.org", "domains", registrar: :purchase))'

Use a separate token for the registrar, so that the token that creates zones cannot buy names.

An ordinary token acts in its own organisation. A provisioning token names the customer in the X-Salt-Organisation header, as on the provisioning routes. It must send the header on every call tied to a customer or a domain. It may leave it out on the three platform calls (account, check, prices) and then acts for its provider organisation.

2. Which registrar account

The calls use the active provider of the token's own organisation (the oldest that is not turned off). A provisioning token's customers are served by the provider of the provisioning token's own organisation.

A shared provider (one that belongs to no organisation, made by the operator) is used only by the organisations the operator has allowed (SaltDns.Release.registrar_allow/2, from the command line; no console page and no API call can do it). An organisation that is not on the list has no provider through the shared one at any level, reading the account included: every route answers 503 registrar_unavailable with "cause": "no_provider". An allowed organisation's provisioning token serves that organisation's customers too. Giving a token a registrar level on the console is only offered to an organisation that has a provider it may use.

With no provider the answer is 503 registrar_unavailable. Providers are set up in the console (Registrar) or by the operator.

Authentication comes first, as on every route, and may answer before the switch and the level are looked at: a request without a valid token is a 401, and a provisioning token without X-Salt-Organisation on a route that requires it gets 400 organisation_required (or 404 for an organisation that is not its child). A request that passes authentication, with the module switched off, gets 404 not_found (the same as /proxy with routing off), before the level of the token is looked at; so "a valid token gets 404 while the module is off" holds for a request that passes authentication.

Calls through a domain follow the same rule as spending. A route that makes a call to the registrar through a domain, or hands out something secret (reading a pending domain from the registrar, the owner contact's verification state, the authorisation code, renewing, restoring, abandoning an operation, contact changes), needs the caller's own registrar account to be the one the domain is held at: the active provider of the token's own organisation, as described above. A customer organisation with an ordinary token of its own, with or without an account of its own, is not served by its parent's account: it may read the stored record of its domain (GET /registrar/domains, /domains/{fqdn} with verification null, /operations/{reference}) and nothing more. It gets the authorisation code only through the provider's own token; anything else is 503 registrar_unavailable with the cause no_provider, and no call is made.

A body that is not a JSON object (an array, a number, a string, null) is a 422 invalid with the error invalid_body.

Every spending call, contact change, authorisation-code read and abandon keeps the id of the token that asked (never the token itself) and the acting organisation on the operation and on its events. The console's operations list shows the token's name.

3. Which calls spend money

Only register, transfer, renew and restore spend money: PUT /registrar/domains/{fqdn} (with kind register or transfer), POST /registrar/domains/{fqdn}/renew and POST /registrar/domains/{fqdn}/restore. Everything else is free: account, check, prices, contacts, the verification e-mail, reading a domain, the list, the operations and the authorisation code. (Contacts, the verification call and the authorisation code need the purchase level all the same.)

CallLevelHeaderAnswer
GET /registrar/accountreadoptionalbalance and reserved (money), currency, mode, provider name
POST /registrar/checkreadoptionalper name: status, costs, promotion, periods
GET /registrar/prices?extension=com&period=2readoptionalthe price block of one extension for a period
PUT /registrar/contacts/{ref}purchaserequiredref, version, state
POST /registrar/contacts/{ref}/verificationpurchaserequiredsends the e-mail again, returns the state
PUT /registrar/domains/{fqdn}purchaserequiredthe operation: 200 done, 202 pending
PUT /registrar/domains/{fqdn}/name-serverspurchaserequiredthe domain, with its name servers and their glue
GET /registrar/domainsreadrequiredthe organisation's domains
GET /registrar/domains/{fqdn}readrequiredstate, dates, lock, name servers, verification
POST /registrar/domains/{fqdn}/renew, /restorepurchaserequiredthe operation
POST /registrar/domains/{fqdn}/auth-codepurchaserequiredthe code, once
GET /registrar/operations/{reference}readrequiredthe ledger row
POST /registrar/operations/{reference}/abandonpurchaserequiredgives up a stuck operation, after a lookup

4. Money

Money has one shape everywhere in the answers: {"minor": 1117, "currency": "USD"}, whole numbers in minor units (cents), never a float. Requests send the price ceiling as cost_ceiling_minor with currency (or as a cost_ceiling object of the same shape). Salt returns cost prices; any fee is yours to add.

The currency is the registrar account's. GET /registrar/account says which it is. A request in another currency is refused as invalid with the field currency named; Salt never converts and never ignores it. On a registration or transfer the currency is required; on a renewal or restore it may be left out and is then the account's.

Nothing is bought on credit and there is no overall spending cap. The only limit is the ceiling of each call; the registrar account's balance is the rest.

An operation shows three amounts:

  • cost_ceiling: the most you accepted;
  • cost_quoted: the price Salt read from the registrar immediately before it ordered, written on the row before the order goes;
  • cost_charged: the same price once the order call itself succeeded. cost_confirmed says whether it is set. An operation completed from a lookup after a lost answer has a quote and no charge (cost_charged null, cost_confirmed false): Salt cannot say what was charged.

5. Checking and prices

POST /registrar/check takes at most 15 names, as {"name": "example", "extension": "org"} or plain "example.org", "fresh": true to skip the price cache (a few minutes) and "period" (years, default 1, for all names). GET /registrar/prices?extension=com&period=2 gives the same block for one extension. For that period, each answer has:

  • costs.create, costs.renew, costs.transfer: totals for the period, read from the registrar with the period and never multiplied (a promotion often covers the first year only, so two years can cost far more than twice one). costs.restore is one restore.
  • costs.renew_yearly: the price of renewing for one year, what a customer pays each year afterwards.
  • promotion: null, or {"ends_on": "2026-12-31", "non_promotion": {money}}, where non_promotion is the price for the same period without the promotion.
  • min_period, max_period, privacy_allowed, quarantine_days, soft_quarantine_days, fetched_at. For a name, also status (free, taken, premium, unavailable).

quarantine_days and soft_quarantine_days are two different facts, both in days, passed through as the registrar reports them for the extension. Either may be null or 0. soft_quarantine_days is the period after expiry in which the name can still be renewed or restored before it is deleted, as the registrar defines it. Salt does not interpret either. Live values: .com has quarantine_days 0 and soft_quarantine_days 40; .nl has quarantine_days 38 and soft_quarantine_days 0.

Reads are kept from becoming calls to the registrar at the caller's pace: whether a name is free is kept for 2 minutes per name ("fresh": true asks again), the price lists for a few minutes per extension and period, a pending domain is read from the registrar at most once a minute, and the verification state of the owner contact is kept for a minute.

A period outside min_period and max_period is 422 invalid with the field period. An extension the registrar does not sell is 422 unsupported_extension. The cache is per extension and period. For a period longer than one year costs.create is the price of the extension, not of the name; a premium name is priced when it is ordered, against your ceiling.

6. Contacts

PUT /registrar/contacts/{ref} with the registrant's data (name with first_name and last_name, company_name, email, phone, address, locale) and a version. Salt sends the data to the registrar and keeps only your reference, the version and the registrar's handle. The same version again sends nothing; a higher one updates the contact at the registrar; an older one is refused. A refusal by the registrar is 422 invalid_contact with the fields in errors. The body is never written to a log. Admin, tech and billing contacts of every name are the provider's company contact; you send only the owner.

7. Registering, transferring, renewing, restoring

A registration is told from a transfer by the kind field of PUT /registrar/domains/{fqdn}: "register" or "transfer". auth_code is sent only with a transfer (and required there). Neither needs a zone for the name in Salt first: the registrar module only sets the name servers on the name at the registrar. Zones are created by the caller through the existing zone routes.

PUT /api/v1/registrar/domains/example.org
{"reference": "order-17", "kind": "register", "years": 1, "contact_ref": "owner-9",
 "privacy": true, "cost_ceiling_minor": 1500, "currency": "USD"}
  • reference is yours and unique per organisation. The same reference with the same request returns the stored result and buys nothing, also while the first call is still running. The same reference with another request is 409 reference_reuse. After an error with final: false, call again with the same reference: Salt first looks the name up at the registrar before it orders anything (see section 9).
  • cost_ceiling_minor (with currency) is the most you accept to pay for the whole period. Salt reads the price again immediately before it orders and refuses with 409 price_above_ceiling (with current_cost) if it is higher or in another currency.
  • A premium name is refused (422 invalid) unless "allow_premium": true.
  • kind: "transfer" needs auth_code (sent to the registrar, never stored or logged) and is usually 202 pending. Renew and restore take reference, years (renew), cost_ceiling_minor and optionally currency (the currency of the registrar account when left out).
  • Salt sets its own name servers on a new name and turns the registrar's automatic renewal off. It does not create a DNS zone. Send name_servers to use others: a list of host names or objects with name and the optional ipv4 and ipv6. A name server that is the domain itself or under it needs an address (glue), or the request is 422 invalid; an address on one outside the domain is 422 too (a registry ignores or refuses it, and Salt does not drop it silently). Left out, Salt's own name servers are used.
  • 200 means done (dates and the amounts of section 4 in the answer); 202 means pending (the registrar has not finished) or started (a repeat while the first call is still running): read GET /registrar/operations/{reference} or the domain until it is done. A background job also resolves pending operations and finishes operations that were cut short; it never places an order itself.

Name servers and glue

PUT /registrar/domains/{fqdn}/name-servers replaces them without spending money:

{"name_servers": [
  {"name": "ns1.trouweherverdeling.nl", "ipv4": "65.109.158.98"},
  {"name": "ns2.trouweherverdeling.nl", "ipv4": "65.108.4.21", "ipv6": "2a01:7c8::21"}
]}

The answer is the domain, with name_servers (the host names) and name_server_addresses (the glue, keyed by name server; only the families present). sync_domain (the daily read, and a read of a pending domain) keeps the addresses the registrar reports, so a later change that names the same server without an address keeps its stored glue.

8. Errors

Problem documents, type urn:salt-dns:problem:<code>. Every error body of the registrar routes carries "final": true|false, and a 503 or 429 says why in "cause" when it can be told:

CodeStatusfinalMeaning
insufficient_funds402trueThe registrar account cannot pay; nothing was bought.
name_unavailable409trueThe name cannot be registered, or is held or being ordered.
price_above_ceiling409trueHas current_cost and cost_ceiling (money).
reference_reuse409trueThe reference belongs to another request.
locked409trueThe name is locked, or in a state that forbids it.
invalid, invalid_contact422trueThe request is wrong; errors lists the fields.
unsupported_extension422trueThe registrar does not sell that extension.
rate_limited429falseRetry-After and retry_after say how long to wait. cause: rate_limited.
registrar_unavailable503falsecause: registrar_login (Salt's own login at the registrar fails; its text is not shown), network, registrar_error (a server error), no_provider (no registrar account is configured).
not_found404trueNo such domain, contact or operation.
provider502falseAny other registrar problem.
operation_not_abandonable409trueThe operation is done or failed.
operation_in_progress409falseA call may still be running; try again later.
too_early409falseAbandon found nothing at the registrar, but the last attempt is too young to conclude that nothing was ordered (a timed-out order may still complete). Nothing changed; Retry-After and retry_after say how many seconds to wait.
forbidden403trueThe token's registrar level is too low.
organisation_required400trueA provisioning token must name the customer in X-Salt-Organisation.

For an error on a route with no reference, final is whether repeating the identical call can succeed.

9. Retrying and references

  • After an error with final: false (rate_limited, registrar_unavailable, provider), repeat the call with the same reference. Salt looks the name up at the registrar first and completes the operation from what it finds; it orders only if the name is not there.
  • After an error with final: true, the reference is burned: the same reference gets the same answer for ever. Make a new reference for the next attempt (with a new quote if the price moved).
  • A good form is <order id>-<attempt>: order-17-1, then order-17-2.
  • If an operation is stuck for good (it stays started after the retries), POST /registrar/operations/{reference}/abandon looks the name up and tells you plainly what it found:
{"outcome": "nothing_ordered", "operation": {"state": "failed", "...": "..."}}

nothing_ordered: the registrar shows no such name in the account; the operation is failed and final, and it is safe to refund. registered: the name is at the registrar; the operation was completed instead, so do not refund. If the lookup itself fails the answer is 503 (final: false) and nothing changes. It is 409 for an operation that is done or failed, that may still be running, or (too_early) whose last attempt is younger than the stale time while the lookup finds nothing: wait the retry_after seconds.