punos

Punos API

General

Everything the web interface does can be done through the Punos API: zones, records, networks and addresses.

ItemValue
Addresshttps://app.punos.cloud/v1
FormatJSON (UTF-8); requests carry Content-Type: application/json
AuthenticationAuthorization: Bearer <API-token>
Machine-readable descriptionhttps://app.punos.cloud/v1/openapi.json (OpenAPI)
Rate limit600 requests a minute per IP address; beyond that 429 with a Retry-After header
Largest request1 MB

Every customer path starts with /v1/tenants/{tenant_id}. Your identifier is shown on the API tokens page of the web interface. Unknown fields in a request are refused (422), and every response carries an X-Request-Id header you can give to support.

The examples use these variables:

API=https://app.punos.cloud/v1
TOKEN=pt_...            # API token
T=<tenant_id>
H="Authorization: Bearer $TOKEN"
J="Content-Type: application/json"

Authentication

The API is used with an API token. A signed-in admin or owner creates one on the API tokens page of the web interface.

  • The token is shown once, when created. Punos stores only its hash.
  • A token has a role and a lifetime (1–365 days, 90 by default).
  • A token belongs to one customer and does not work on another customer's paths.
  • A token cannot create tokens or manage users.
  • Revoking it in the web interface takes effect at once.
Token roleMay
viewerread zones, records, networks and addresses, and search
editoralso change records, networks and addresses
adminalso add and delete zones, create spaces and read the audit log
curl -s "$API/tenants/$T" -H "$H"

The answer gives the customer's name, the token's role, the limits and the nameservers. Give each integration its own token and the smallest role that is enough.

Zones

A zone is served only once ownership of the domain has been proven with a TXT record at the domain's current DNS provider. Every zone is signed with DNSSEC automatically.

RequestRoleWhat it does
GET /tenants/{t}/zonesviewerlists the zones
POST /tenants/{t}/zonesadminadds a zone as pending and returns the verification record
GET /tenants/{t}/zones/{zone_id}viewerone zone
POST /tenants/{t}/zones/{zone_id}/verifyadminchecks the TXT record and activates the zone
GET /tenants/{t}/zones/{zone_id}/dnssecviewerDS records for the registrar
DELETE /tenants/{t}/zones/{zone_id}admindeletes the zone; body {"confirm": "<zone name>"}
curl -s -X POST "$API/tenants/$T/zones" -H "$H" -H "$J" -d '{"name": "example.fi"}'

{
  "id": "da9e9d90-b383-4277-aaa5-c5581d3ee7d2",
  "name": "example.fi.",
  "status": "pending",
  "challenge": {
    "name": "_punos-challenge.example.fi.",
    "type": "TXT",
    "value": "punos-verify=3f9c..."
  }
}

Add the challenge record to the domain's current DNS and then call verify. If the record is not visible yet the answer is 409 with code not_verified, and the call can be repeated. A domain, or a name above or below it, can be active for one customer only.

Records

Records are handled as sets (rrsets): one name and type, its TTL and all its values. Changes are sent as a batch that is applied as a whole or not at all, and reach the nameservers in a few seconds.

RequestRoleWhat it does
GET /tenants/{t}/zones/{zone_id}/rrsetsviewerlists; parameters name, type, limit (at most 1000), offset
PATCH /tenants/{t}/zones/{zone_id}/rrsetseditora batch of 1–500 changes
curl -s -X PATCH "$API/tenants/$T/zones/$Z/rrsets" -H "$H" -H "$J" -d '{
  "changes": [
    {"name": "www", "type": "A", "ttl": 300, "records": ["192.0.2.10", "192.0.2.11"]},
    {"name": "@",   "type": "MX", "ttl": 3600, "records": ["10 mail"]},
    {"name": "@",   "type": "TXT", "ttl": 3600, "records": ["v=spf1 -all"]},
    {"name": "old", "type": "CNAME", "delete": true}
  ]
}'
FieldContent
name@ is the zone itself; a relative name (www) or a full name with a dot (www.example.fi.)
typeA, AAAA, CAA, CNAME, DS, MX, NS, PTR, SRV, SSHFP, TLSA, TXT
ttl30–604800 seconds
records1–100 values in zone-file form; a relative target (mail) is taken to be inside the zone
deletetrue deletes the set; then no ttl or records

A TXT value can be given without quotes. Values are stored normalised, so a listing may return them in a slightly different form than you sent. The zone's own NS and SOA records cannot be changed. One invalid value refuses the whole batch (422, invalid_record).

IPAM

IPAM consists of spaces, networks and addresses. A space is a separate address space: the same network can exist in two spaces. Every customer starts with the space default. The network tree follows from the addresses themselves.

RequestRoleWhat it does
GET /tenants/{t}/ipam/spacesviewerthe spaces
POST /tenants/{t}/ipam/spacesadmina new space
GET /tenants/{t}/ipam/networks?space_id=…viewerthe networks of a space, with parent_id, depth, address_count, hosts
POST /tenants/{t}/ipam/networkseditora new network
GET /tenants/{t}/ipam/networks/{id}viewera network, its parents, subnets and addresses
PATCH /tenants/{t}/ipam/networks/{id}editorchanges name, description, VLAN or tags
DELETE /tenants/{t}/ipam/networks/{id}editordeletes the network; subnets and addresses are kept
POST /tenants/{t}/ipam/networks/{id}/next-networkeditorcreates the next free subnet
POST /tenants/{t}/ipam/networks/{id}/next-addresseditorrecords the network's next free address
GET /tenants/{t}/ipam/addresses?space_id=…viewerthe addresses of a space
POST /tenants/{t}/ipam/addresseseditorrecords an address
PATCH, DELETE /tenants/{t}/ipam/addresses/{id}editorchanges or deletes an address
curl -s -X POST "$API/tenants/$T/ipam/networks" -H "$H" -H "$J" -d '{
  "space_id": "'$SPACE'", "cidr": "10.20.0.0/16", "name": "Suomi",
  "vlan": 20, "tags": {"maa": "FI"}
}'

A network address must be exact: 10.20.0.1/16 is refused and the error suggests 10.20.0.0/16. An address has the fields ip, status (used or reserved), hostname, mac, description and tags.

Next free network and address

These two calls are made for automation. They allocate and record the result in one step, and two simultaneous calls never get the same answer.

curl -s -X POST "$API/tenants/$T/ipam/networks/$NET/next-network" -H "$H" -H "$J" \
  -d '{"prefix_len": 24, "name": "Tampere LAN", "tags": {"site": "TRE"}}'

curl -s -X POST "$API/tenants/$T/ipam/networks/$NET/next-address" -H "$H" -H "$J" \
  -d '{"hostname": "printer-tre-01", "status": "used"}'

Errors

An error always has the same shape. A program should act on code; message is for people and may change.

{
  "error": {
    "code": "invalid_record",
    "message": "change 2 (bad A): invalid A record: '999.1.1.1'",
    "request_id": "e744226acd724ac1946291749809c24c"
  }
}
HTTPCodeWhen
401unauthorizedthe token is missing, wrong, expired or revoked
403forbiddenthe token's role is not enough
404not_foundno such thing, or it belongs to another customer
409zone_exists, zone_taken, not_verified, zone_not_activethe zone's state prevents the request
409network_exists, address_exists, space_existsit already exists
409no_free_network, no_free_addressnothing free is left
409zone_limit, record_limit, network_limit, address_limitthe customer's limit is reached
422invalid_request, invalid_zone_name, invalid_record, invalid_cidr, invalid_ipa field or value of the request is not valid
422rejected_by_dnsthe nameserver refused the change, for example a CNAME beside another record
429rate_limitedtoo many requests; wait as long as Retry-After says
502, 503dns_backend_error, verification_unavailablea temporary fault; try again shortly

Example: a new site, automatically

A new site gets a network, an address for its gateway and a DNS name for that address in three calls.

# 1. Next free /24 inside the network $FI
NET=$(curl -s -X POST "$API/tenants/$T/ipam/networks/$FI/next-network" -H "$H" -H "$J" \
  -d '{"prefix_len": 24, "name": "Tampere", "tags": {"site": "TRE"}}')
NET_ID=$(echo "$NET" | jq -r .id); CIDR=$(echo "$NET" | jq -r .cidr)

# 2. First free address of that network, for the gateway
GW=$(curl -s -X POST "$API/tenants/$T/ipam/networks/$NET_ID/next-address" -H "$H" -H "$J" \
  -d '{"hostname": "gw-tre.example.fi"}' | jq -r .ip)

# 3. A DNS name for the address ($Z is the id of the zone example.fi)
curl -s -X PATCH "$API/tenants/$T/zones/$Z/rrsets" -H "$H" -H "$J" \
  -d '{"changes": [{"name": "gw-tre", "type": "A", "ttl": 3600, "records": ["'$GW'"]}]}'

echo "$CIDR $GW"

In a script, check each call's HTTP status before the next: if step 2 or 3 fails, the network allocated in step 1 is already recorded.