网页控制台中的所有操作(添加和删除域名、管理 DNS 记录)都可以通过 REST API 以编程方式完成。
所有接口均使用 JSON 进行请求和响应。认证需要使用 API 密钥(见下文)。目前没有分页,也没有速率限制。
https://ns.nrnic.com/api
API 密钥可在账户设置中生成。新生成的密钥只会显示一次,请务必妥善保存。
请在每个请求中添加如下 Authorization 请求头:
Authorization: Bearer nrnic_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
发生错误时,将返回相应的 HTTP 状态码(401/404/409/422/500 等)以及如下格式的 JSON。
{
"error": {
"code": "domain_not_found",
"message": "Domain not found."
}
}
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /api/domains | 获取当前用户的域名列表 |
| POST | /api/domains | 添加域名 |
| GET | /api/domains/{id} | 获取域名详情(包含 NS 同步状态和委派状态) |
| DELETE | /api/domains/{id} | 删除域名 |
| POST | /api/domains/{id}/resync | 将 DNS 区域重新推送到所有域名服务器(ns1–ns4) |
| POST | /api/domains/{id}/delegation-check | 检查域名是否已委派给 NRNIC |
| GET | /api/domains/{id}/records | 获取域名的 DNS 记录列表 |
| POST | /api/domains/{id}/records | 添加 DNS 记录 |
| PUT | /api/domains/{id}/records/{record_id} | 更新 DNS 记录 |
| DELETE | /api/domains/{id}/records/{record_id} | 删除 DNS 记录 |
# 获取当前用户的域名列表curl -s https://ns.nrnic.com/api/domains \
-H "Authorization: Bearer nrnic_xxxxxxxx"
# 添加域名curl -s https://ns.nrnic.com/api/domains \
-H "Authorization: Bearer nrnic_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"fqdn": "example.com"}'
# 删除域名curl -s -X DELETE https://ns.nrnic.com/api/domains/123 \
-H "Authorization: Bearer nrnic_xxxxxxxx"
# 添加 DNS 记录curl -s https://ns.nrnic.com/api/domains/123/records \
-H "Authorization: Bearer nrnic_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"type": "A", "name": "@", "content": "192.0.2.1", "ttl": 3600}'
# 更新 DNS 记录curl -s -X PUT https://ns.nrnic.com/api/domains/123/records/456 \
-H "Authorization: Bearer nrnic_xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"type": "A", "name": "@", "content": "192.0.2.2", "ttl": 3600}'
# 删除 DNS 记录curl -s -X DELETE https://ns.nrnic.com/api/domains/123/records/456 \
-H "Authorization: Bearer nrnic_xxxxxxxx"
| type | 记录类型。可选 A、AAAA、CNAME、MX、TXT、NS、SRV、CAA 之一。 |
| name | 主机名(子域名部分)。区域顶点请使用 "@"。 |
| content | 记录的值(IP 地址、目标主机名等)。 |
| ttl | TTL(秒),范围 60–604800。省略时默认为 3600。 |
| priority | MX/SRV 记录的优先级(0–65535)。 |
| weight | SRV 记录的权重(0–65535)。 |
| port | SRV 记录的端口号(0–65535)。 |