DNS API

Manage authoritative DNS zones and records in Ravicor through external integrations, and query recursive DNS statistics. This is the same API used to publish records automatically from ISP ERPs and panels.

Overview

The dns area of the public API lets you create and delete zones (domains), create, search and delete records (subdomains) in the Authoritative DNS, and read the server's recursive DNS statistics. The typical use case is the ISP's management system creating zones and records on its own, without anyone having to open the Ravi screen.

Record creation via API accepts the priority parameter (for MX records) and batch mode with defer_reload + reload_nsd.

Prerequisites

  • An API key with the DNS Access permission checked. Keys are created in Settings, the Integrations tab, the API Management card (only the Master account manages keys Master only). See Create an API key.
  • The Ravi DNS environment installed and active (DNS area of the menu). The recursive operation returns the last statistics collected from the recursive DNS (it must have collected data at least once; the current service state comes in the service_status block); the authoritative operations require the authoritative server managed by Ravi.
  • Without the permission, the gateway returns HTTP 403 with {"status":"error","message":"Access denied for dns"}. An invalid token returns HTTP 401.

Call and response format

All operations use the single API endpoint, via GET or POST:

base URL
https://YOUR-SERVER/api/api.php?token=KEY&action=dns&operation=OPERATION&...

The DNS module returns JSON directly, without an envelope: success comes as {"msg":"ok"} (on mutations) or as the requested object (e.g. {"authoritative":[...]}). Business errors come with HTTP 200 and the text in English in the msg field.

Do not rely on the HTTP code alone: in this module, any response whose msg is different from "ok" must be treated as an error. Only gateway errors (token, permission, action) use HTTP codes 400/401/403.

Common parameters

ParameterAccepted aliasUse
operation-Required on every call.
domaindomTarget zone (e.g. provedor.com.br).
subdomainsubdomRecord name (e.g. www, @, mail).
typetipoRecord type: A, AAAA, CNAME, MX, NS, PTR, TXT (SRV is accepted if the host value includes priority, weight and port).
host-Record value/target (IP, hostname or TXT text).
comment-Free comment stored on the record (optional).
adicionalalt_domainPTR only: alternative domain (optional; no spaces or special characters).
priorityprioridadeNumeric priority for MX records (optional).
defer_reload-1 = do not reload the authoritative server on this call (batch mode; see reload_nsd).

Automatic behavior

  • Every mutation (create/delete a zone or record) without defer_reload regenerates and signs the zones and reloads the authoritative server (NSD) synchronously: the response takes about 1.5 to 2 seconds longer. Do not treat this as abnormal slowness.
  • When creating a zone via API, the system automatically creates 3 A records: ns1, ns2 and www, pointing to the detected IPs of the server itself. With 2 IPs, ns1 uses the first and ns2 the second; with 1 IP, both use the same one; with no detectable IP, they are set to 0.0.0.0 for the operator to adjust.
  • Deleting a zone also deletes the reverse DNS records linked to it.
  • The recursive statistics reflect the DNS module's last collection cycle, not an absolute real-time snapshot.

Operations

The module accepts 8 operations. The read operations work fine via GET; for mutations, prefer POST over HTTPS, because the key travels in the request.

GET /api/api.php?action=dns&operation=recursive

Returns the server's recursive DNS statistics: service status, query and cache metrics, security indicators (DNSSEC) and the size of the active blocklists.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.

Response blocks:

  • service_status: unbound_active (service actually active) and unbound_enabled (recursive turned on in the Ravi options).
  • current_metrics: queries per second, average and median response time, cache hit ratio (%), DNSSEC validation ratio (%) and query totals.
  • query_types: count by type (A, AAAA, PTR, CNAME, ANY).
  • security_metrics: DNSSEC validations, bogus responses, unwanted queries and replies.
  • network_metrics: TCP and IPv6 queries.
  • cache_metrics: cache size and request queue.
  • blocklists: number of entries in each active blocklist (only the categories enabled on the DNS screen appear; possible keys: adware_malware, phishing, anatel, cryptomining, ads, adult, social, games_gambling, tracking_analytics, fake_news).
curl
curl -s "https://ravi.seuprovedor.com.br/api/api.php?token=YOUR_KEY&action=dns&operation=recursive"
response (abridged)
{
  "recursive": {
    "service_status":  { "unbound_active": true, "unbound_enabled": true },
    "current_metrics": { "queries_per_second": 412.7, "cache_hit_ratio": 87.3, "dnssec_validation_ratio": 96.1, ... },
    "query_types":     { "A": 125034, "AAAA": 30211, "PTR": 812, "CNAME": 145, "ANY": 3 },
    "security_metrics":{ "dnssec_validated": 118220, "dnssec_bogus": 4, "unwanted_queries": 51, "unwanted_replies": 12 },
    "network_metrics": { "tcp_queries": 210, "ipv6_queries": 18754 },
    "cache_metrics":   { ... },
    "blocklists":      { "phishing": 41230, "anatel": 1287 }
  }
}

Error: {"msg":"No DNS log data found"} when statistics have never been collected.

GET /api/api.php?action=dns&operation=authoritative

Lists the authoritative DNS zones with their records. Without domain, it returns all zones; with domain, only the given zone.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.
domainstringNoFilters by a specific zone.
curl
curl -s "https://ravi.seuprovedor.com.br/api/api.php?token=YOUR_KEY&action=dns&operation=authoritative&domain=cliente.com.br"
response
{
  "authoritative": [
    {
      "id": 12,
      "domain": "cliente.com.br",
      "entries": [
        { "id": 301, "name": "ns1",  "value": "203.0.113.10", "type": "A",  "host": null, "priority": null, "alt_domain": null },
        { "id": 302, "name": "www",  "value": "203.0.113.20", "type": "A",  "host": null, "priority": null, "alt_domain": null },
        { "id": 303, "name": "@",    "value": "mail.cliente.com.br", "type": "MX", "host": null, "priority": 10, "alt_domain": null }
      ]
    }
  ]
}

Error: {"msg":"No authoritative domains found"}.

Two compatibility details: records created by the 7.2 API carry the label in name and the target in value, but old records created by earlier versions of the interface may come with the semantics swapped (value = label, host = target); check which field is filled in. And a zone with no records returns "entries":"null" as the string "null", not as the JSON null value.

POST /api/api.php?action=dns&operation=add_domain

Creates a zone in the authoritative DNS, already with the default records ns1, ns2 and www (type A, pointing to the server's own IPs), and reloads the authoritative server.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.
domainstringYesZone to create (e.g. cliente.com.br).
defer_reload1NoSkips the NSD reload on this call (batch mode).
curl
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" \
  -d "operation=add_domain" -d "domain=cliente.com.br"
response
{"msg":"ok"}

Errors: Please provide a valid domain, Domain already exists.

POST /api/api.php?action=dns&operation=add_subdomain

Creates a record inside an existing zone. Repeating name+type with different values is allowed (e.g. @ NS ns1 and @ NS ns2, or several TXT records); only the exact name+type+value combination repeated is rejected.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.
domainstringYesZone where the record will be created.
subdomainstringYesRecord name (www, @, mail...).
typestringYesA, AAAA, CNAME, MX, NS, PTR or TXT (SRV is accepted if the host value includes priority, weight and port).
hoststringYesRecord value/target.
prioritynumberNoPriority for MX records.
commentstringNoFree comment stored on the record.
adicionalstringNoPTR only: publishes the record under the alternative domain instead of the main zone (accepts only letters, numbers, dots and hyphens).
defer_reload1NoSkips the NSD reload on this call (batch mode).

TXT records: send the plain text in host, without quotes. The system adds the quotes in the zone and automatically splits values longer than 255 characters into concatenated blocks, following the DNS standard. Long DKIM keys and SPF records can be sent whole in a single call, with no prior processing.

PTR with an alternative domain: when adicional is provided on a PTR record, the record is published under the alternative domain instead of the main zone. Example: subdomain=host1 with adicional=reverso.exemplo.net creates the PTR as host1.reverso.exemplo.net (with subdomain=@, the published name is the alternative domain itself). The field accepts only letters, numbers, dots and hyphens; any other character returns the error Alternative domain cannot contain spaces or special characters.

curl (MX record)
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=add_subdomain" \
  -d "domain=cliente.com.br" -d "subdomain=@" -d "type=MX" \
  -d "host=mail.cliente.com.br" -d "priority=10"
curl (PTR record with an alternative domain)
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=add_subdomain" \
  -d "domain=exemplo.com" -d "subdomain=host1" -d "type=PTR" \
  -d "host=192.168.1.1" -d "adicional=reverso.exemplo.net"
response
{"msg":"ok"}

Errors: Please provide domain, subdomain, type and host, Domain not found, Entry already exists, Alternative domain cannot contain spaces or special characters (PTR with an invalid adicional).

GET /api/api.php?action=dns&operation=search_subdomain

Checks whether a record exists in the zone. Useful before creating or deleting, and to verify the result of a batch.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.
domainstringYesZone to search in.
subdomainstringYesRecord name.
typestringYesRecord type.
hoststringNoIf provided, the search becomes exact by name+type+value (useful when there are several records with the same name and type).
curl
curl -s "https://ravi.seuprovedor.com.br/api/api.php?token=YOUR_KEY&action=dns&operation=search_subdomain&domain=cliente.com.br&subdomain=www&type=A"
response
{"msg":"true"}

{"msg":"true"} = the record exists; {"msg":"false"} = it does not exist. Error: Domain not found.

DEL /api/api.php?action=dns&operation=delete_subdomain

Deletes a record from the zone. The lookup is done by name+type, without considering the value.

If there are several records with the same name and type (e.g. two NS, several TXT), the deletion removes the first one that matches and you cannot choose which. Remove one per call and check the result with authoritative before repeating.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.
domainstringYesZone of the record.
subdomainstringYesName of the record to delete.
typestringYesType of the record to delete.
defer_reload1NoSkips the NSD reload on this call (batch mode).
curl
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=delete_subdomain" \
  -d "domain=cliente.com.br" -d "subdomain=www" -d "type=A"
response
{"msg":"ok"}

Errors: Subdomain not found, Domain not found.

DEL /api/api.php?action=dns&operation=delete_domain

Deletes an entire zone from the authoritative DNS.

The deletion is irreversible and removes the zone, all of its records and also the linked reverse DNS records. Confirm the zone before calling.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.
domainstringYesZone to delete.
defer_reload1NoSkips the NSD reload on this call (batch mode; see reload_nsd). Zone deletion triggers the same automatic reload as the other mutations and honors the parameter in the same way.
curl
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" \
  -d "operation=delete_domain" -d "domain=cliente.com.br"
response
{"msg":"ok"}

Error: Domain not found.

POST /api/api.php?action=dns&operation=reload_nsd

Reloads the authoritative server on demand. It is the counterpart of defer_reload: when creating or changing many records, send defer_reload=1 on each mutation (skipping the individual reload) and call reload_nsd once at the end. The result is 1 reload instead of N, and the batch runs much faster.

ParameterTypeRequiredDescription
tokenstringYesAPI key with DNS Access.

The call waits for the Ravi service to process the reload, for up to 15 seconds.

curl
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=reload_nsd"
response
{"msg":"ok","reload_confirmed":true,"waited_ms":1800}

If the wait exceeds the 15 seconds, the response comes as {"msg":"ok_reload_timeout","reload_confirmed":false,...}: the reload may still complete shortly after; confirm with dig and, if needed, repeat the call.


Practical examples

Create a zone and an MX record

The most common integration flow: create the customer's zone and publish a record. The same pattern applies to A, AAAA, CNAME, TXT and the other types.

# 1) create the zone (ns1/ns2/www are created automatically)
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" \
  -d "operation=add_domain" -d "domain=cliente.com.br"

# 2) create the MX record
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=add_subdomain" \
  -d "domain=cliente.com.br" -d "subdomain=@" -d "type=MX" \
  -d "host=mail.cliente.com.br" -d "priority=10"

# 3) verify
curl -s "https://ravi.seuprovedor.com.br/api/api.php?token=YOUR_KEY&action=dns&operation=search_subdomain&domain=cliente.com.br&subdomain=@&type=MX&host=mail.cliente.com.br"
<?php
$base  = 'https://ravi.seuprovedor.com.br/api/api.php';
$token = 'YOUR_KEY';

function dnsApi($params) {
    global $base, $token;
    $params += ['token' => $token, 'action' => 'dns'];
    $ch = curl_init($base);
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => http_build_query($params),
        CURLOPT_RETURNTRANSFER => true,
    ]);
    $resp = json_decode(curl_exec($ch), true);
    curl_close($ch);
    // in this module, msg != "ok" means an error (even with HTTP 200)
    if (isset($resp['msg']) && strpos($resp['msg'], 'ok') !== 0
        && !in_array($resp['msg'], ['true', 'false'], true)) {
        throw new Exception('DNS API: ' . $resp['msg']);
    }
    return $resp;
}

dnsApi(['operation' => 'add_domain', 'domain' => 'cliente.com.br']);
dnsApi([
    'operation' => 'add_subdomain',
    'domain'    => 'cliente.com.br',
    'subdomain' => '@',
    'type'      => 'MX',
    'host'      => 'mail.cliente.com.br',
    'priority'  => 10,
]);
import requests

BASE  = "https://ravi.seuprovedor.com.br/api/api.php"
TOKEN = "YOUR_KEY"

def dns_api(**params):
    params.update(token=TOKEN, action="dns")
    resp = requests.post(BASE, data=params, timeout=30).json()
    # in this module, msg != "ok" means an error (even with HTTP 200)
    msg = resp.get("msg", "ok")
    if not msg.startswith("ok") and msg not in ("true", "false"):
        raise RuntimeError(f"DNS API: {msg}")
    return resp

dns_api(operation="add_domain", domain="cliente.com.br")
dns_api(operation="add_subdomain", domain="cliente.com.br",
        subdomain="@", type="MX",
        host="mail.cliente.com.br", priority=10)

Batch of records with a single reload

Each mutation reloads the authoritative server and costs 1.5 to 2 seconds. To publish several records at once (e.g. SPF, DKIM and MX of an email domain), use defer_reload=1 on each call and close the batch with reload_nsd.

curl
# mutations without individual reload
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=add_subdomain" \
  -d "domain=cliente.com.br" -d "subdomain=@" -d "type=TXT" \
  -d "host=v=spf1 mx -all" -d "defer_reload=1"

curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=add_subdomain" \
  -d "domain=cliente.com.br" -d "subdomain=mail" -d "type=A" \
  -d "host=203.0.113.25" -d "defer_reload=1"

# a single reload, at the end of the batch
curl -s -X POST "https://ravi.seuprovedor.com.br/api/api.php" \
  -d "token=YOUR_KEY" -d "action=dns" -d "operation=reload_nsd"

If you use defer_reload=1 and forget to call reload_nsd at the end, the changes are stored but do not take effect in DNS until the next reload. If dig still returns the old value after a batch, this is usually the reason.

Migrating from the old webservice

Integrations that used the old /webservice/ endpoints (authentication by system token + username and password in the URL) stopped working in 7.2 and must migrate to /api/api.php with an API key. Mapping of the calls:

Legacy callReplacement in the current API
webservice/dns.php?acao=recursivoaction=dns&operation=recursive
...acao=autoritativooperation=authoritative
...acao=add_domoperation=add_domain
...acao=add_subdomoperation=add_subdomain
...acao=pesquisar_subdomoperation=search_subdomain
...acao=delete_subdomoperation=delete_subdomain
...acao=delete_domoperation=delete_domain

Beyond working again, the migration swaps a username and password in plain text in the URL for a revocable key with permission restricted to the DNS area.

Troubleshooting

SymptomLikely cause
HTTP 403 Access denied for dnsThe key exists, but the DNS Access permission is not checked. The Master account can adjust the key in Settings, the Integrations tab.
{"msg":"ok"}, but dig still returns the old valueReload in progress (it is synchronous, but there is propagation and caching), or use of defer_reload=1 without calling reload_nsd at the end of the batch.
reload_nsd returns ok_reload_timeoutThe Ravi service was busy and the confirmation took more than 15 seconds. The reload usually completes right after; check with dig and repeat if needed.
A created record does not appear as expected in authoritativeCheck the name and value fields: old records created by the interface of earlier versions may come with the semantics swapped.
{"msg":"No DNS log data found"} in recursiveThe recursive DNS has never collected statistics on this server; confirm that the recursive is active in the DNS area.

Best practices: use HTTPS and POST (the key travels in the request); create a dedicated key for the DNS integration, with only DNS Access checked; in batches, always defer_reload=1 + a final reload_nsd.