更新DNS记录¶
1. 接口描述¶
接口请求路径:POST /prod-api/acdn/ccdn/dnsRecordsRest/updateDNSRecords
updateDNSRecords 用于更新指定主域名下已有的 DNS 记录。账号需具备 ccdn:domain:edit 权限。
Token 获取方式见 密钥鉴权。
注意:
zoneId必须为当前账号下的域名,dnsRecordId取自 查询DNS记录列表 返回的data.result[].id。name传完整记录名;根域名传主域名本身,如example.com。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| zoneId | 是 | String | 域名 Zone ID。示例值:551290393816e70c5e9765ca020e30a4 |
| dnsRecordId | 是 | String | DNS 记录 ID。示例值:023e105f4ecef8ad9ca31a8372d0c353 |
| type | 是 | String | 记录类型。取值:CNAME(回源到域名)、A(回源到 IP)。示例值:CNAME |
| name | 是 | String | 主机名(完整记录名)。示例值:www.example.com |
| content | 是 | String | 回源地址。type 为 CNAME 时填回源域名,A 时填 IP 地址。示例值:origin.example.com |
| proxied | 否 | Boolean | 状态。是否启用 CDN 加速。示例值:true |
| ttl | 否 | String | TTL(秒),1 表示自动;proxied 为 true 时只能为 1。示例值:1 |
| comment | 否 | String | 注释。示例值:官网加速 |
3. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:成功 |
| data | String | 上游接口返回的 JSON 字符串,包含更新后的记录详情 |
4. 示例¶
示例1 更新 DNS 记录¶
输入示例¶
{
"zoneId": "551290393816e70c5e9765ca020e30a4",
"dnsRecordId": "023e105f4ecef8ad9ca31a8372d0c353",
"type": "CNAME",
"name": "www.example.com",
"content": "origin2.example.com",
"proxied": true,
"ttl": "1",
"comment": "官网加速"
}
代码调用¶
请将 {登录域名}、token 替换为实际值。
curl -X POST 'https://{登录域名}/prod-api/acdn/ccdn/dnsRecordsRest/updateDNSRecords' \
-H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"zoneId": "551290393816e70c5e9765ca020e30a4",
"dnsRecordId": "023e105f4ecef8ad9ca31a8372d0c353",
"type": "CNAME",
"name": "www.example.com",
"content": "origin2.example.com",
"proxied": true,
"ttl": "1",
"comment": "官网加速"
}'
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class UpdateDNSRecordsTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/acdn/ccdn/dnsRecordsRest/updateDNSRecords";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{"
+ "\"zoneId\":\"551290393816e70c5e9765ca020e30a4\","
+ "\"dnsRecordId\":\"023e105f4ecef8ad9ca31a8372d0c353\","
+ "\"type\":\"CNAME\","
+ "\"name\":\"www.example.com\","
+ "\"content\":\"origin2.example.com\","
+ "\"proxied\":true,"
+ "\"ttl\":\"1\","
+ "\"comment\":\"官网加速\""
+ "}";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", "Bearer " + token);
httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int statusCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println("Status Code: " + statusCode);
System.out.println("Body: " + body);
}
}
}
}
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://{登录域名}/prod-api/acdn/ccdn/dnsRecordsRest/updateDNSRecords"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"zoneId": "551290393816e70c5e9765ca020e30a4",
"dnsRecordId": "023e105f4ecef8ad9ca31a8372d0c353",
"type": "CNAME",
"name": "www.example.com",
"content": "origin2.example.com",
"proxied": true,
"ttl": "1",
"comment": "官网加速"
}`)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println("Body:", string(body))
}
输出示例¶
{
"msg": "成功",
"code": 200,
"data": "{\"success\":true,\"errors\":[],\"messages\":[],\"result\":{\"id\":\"023e105f4ecef8ad9ca31a8372d0c353\",\"name\":\"www.example.com\",\"type\":\"CNAME\",\"content\":\"origin2.example.com\",\"proxied\":true,\"ttl\":1}}"
}
5. 错误码¶
更新失败时,code 为 500,原因在 msg,没有 data。
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 更新成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限,需具备 ccdn:domain:edit |
| zoneId 不能为空 | 未传 zoneId |
| 无效的zoneId | zoneId 不存在或不属于当前账号 |
| 找不到dns解析记录,请确认dnsRecordId是否正确 | dnsRecordId 不存在 |