網頁控制台中的所有操作(新增與刪除網域、管理 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)。 |