跳转至

创建域名

1. 接口描述

接口请求路径:POST /prod-api/acdn/tcdn/domainRest/addDomain

addDomain 用于在指定 TCDN 套餐下新增加速域名。账号需具备 tcdn:CreateDomain 权限。

Token 获取方式见 密钥鉴权。

注意:

  • oid 须为当前账号下的 TCDN 套餐号,取自 查询套餐列表 返回的 rows[].oid,且套餐剩余可接入域名数量足够。
  • addCdnDomainRequest 会原样提交。domain、serviceType、origin 必填。projectId 无需传递,服务端在调用前写入平台项目 ID。

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。

参数名称 必选 类型 描述
oid 是 String 套餐号,取自 查询套餐列表 的 rows[].oid。示例值:20250527123456132123
tags 否 Array of String 资源标签,元素格式为 key:value。仅在域名和解析都创建成功后绑定。不传则不绑定。示例值:["env:prod"]
addCdnDomainRequest 是 AddCdnDomainRequest 加速域名配置

3. 输出参数

新增域名调用失败时,本接口仍返回 code 为 200、msg 为 成功。是否创建成功以 data.errorCode 为准,success 表示域名、本地记录和 DNS 解析均已创建。

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:成功
data ResponseMetadata 创建结果

4. 示例

示例1 新增加速域名

输入示例

{
  "oid": "202505271234561329409",
  "tags": ["env:prod"],
  "addCdnDomainRequest": {
    "domain": "www.test.com",
    "serviceType": "web",
    "area": "mainland",
    "origin": {
      "originPullProtocol": "http",
      "originType": "ip",
      "serverName": "www.test.com",
      "origins": ["1.1.1.1"]
    }
  }
}

代码调用

请将 {登录域名}、token 替换为实际值。

curl -X POST 'https://{登录域名}/prod-api/acdn/tcdn/domainRest/addDomain' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "oid": "202505271234561329409",
  "tags": ["env:prod"],
  "addCdnDomainRequest": {
    "domain": "www.test.com",
    "serviceType": "web",
    "area": "mainland",
    "origin": {
      "originPullProtocol": "http",
      "originType": "ip",
      "serverName": "www.test.com",
      "origins": ["1.1.1.1"]
    }
  }
}'
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 AddDomainTest {

    public static void main(String[] args) throws Exception {
        String url = "https://{登录域名}/prod-api/acdn/tcdn/domainRest/addDomain";
        String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";

        String requestBody = "{"
                + "\"oid\":\"202505271234561329409\","
                + "\"tags\":[\"env:prod\"],"
                + "\"addCdnDomainRequest\":{"
                + "\"domain\":\"www.test.com\","
                + "\"serviceType\":\"web\","
                + "\"area\":\"mainland\","
                + "\"origin\":{"
                + "\"originPullProtocol\":\"http\","
                + "\"originType\":\"ip\","
                + "\"serverName\":\"www.test.com\","
                + "\"origins\":[\"1.1.1.1\"]"
                + "}"
                + "}"
                + "}";

        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/tcdn/domainRest/addDomain"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "oid": "202505271234561329409",
  "tags": ["env:prod"],
  "addCdnDomainRequest": {
    "domain": "www.test.com",
    "serviceType": "web",
    "area": "mainland",
    "origin": {
      "originPullProtocol": "http",
      "originType": "ip",
      "serverName": "www.test.com",
      "origins": ["1.1.1.1"]
    }
  }
}`)

    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": {
    "errorCode": "success",
    "errorMessage": ""
  }
}

5. 错误码

套餐校验和解析创建失败时,code 为 500,原因在 msg,没有 data。

HTTP 状态码 / 业务提示 描述
200 请求已返回。须再看 data.errorCode
401 未鉴权或 Token 无效
403 无权限,需具备 tcdn:CreateDomain
保存失败,请确认套餐是否正确或已过期 oid 不存在、不属于当前账号,或套餐已过期
保存失败,查询套餐信息失败 查询套餐额度失败
保存失败,该套餐可使用域名数量不足 套餐未配置可接入域名数量
该套餐可使用域名数量不足 已接入域名数量达到套餐上限
error code:{0},message:{1} 新增域名已成功,但查询 CNAME 失败。{0} 为错误码,{1} 为原因。本地域名记录尚未写入
DNS 返回的失败原因 本地域名记录已写入,但 DNS 解析未创建成功,msg 为解析服务返回的原因。解析后缀和标签不会写入,请先查询域名列表再决定是否重试

新增域名调用失败时 code 仍为 200,msg 仍为 成功,本地域名记录不会写入。data.errorCode、data.errorMessage 为上游返回的错误码和异常信息。

{
  "msg": "成功",
  "code": 200,
  "data": {
    "errorCode": "ResourceInUse.CdnHostExists",
    "errorMessage": "域名已存在。"
  }
}
错误码 描述
UnauthorizedOperation.CdnDomainRecordNotVerified 域名未进行归属权校验
ResourceInUse.CdnHostExists 域名已存在
ResourceInUse.CdnConflictHostExists 域名与已存在域名冲突
ResourceUnavailable.CdnHostNoIcp 域名未备案
InvalidParameter.CdnConfigInvalidHost 域名不符合规范
InvalidParameter.CdnParamError 参数错误
UnauthorizedOperation.CdnHostIsUsedByOther 域名已被其他账号接入
LimitExceeded.CdnHostOpTooOften 域名操作过于频繁

6. 数据模型

配置块字段见对应类型链接。未传的可选配置使用默认值。

AddCdnDomainRequest

待创建的加速域名配置。

参数名称 必选 类型 描述
domain 是 String 加速域名。示例值:www.test.com
serviceType 是 String 业务类型。取值:web(网页小文件)、download(下载大文件)、media(音视频点播)、hybrid(动静加速)、dynamic(动态加速)。示例值:web
origin 是 Origin 源站配置。第三方对象存储时 originType 填 third_party,并设置 originCompany:aws_s3、ali_oss、hw_obs、qiniu_kodo、others,同时传入对应私有鉴权
area 否 String 加速区域。取值:mainland(中国境内)、overseas(中国境外)、global(全球)。overseas、global 需先开通中国境外加速。示例值:mainland
projectId 否 Integer 项目 ID。服务端会覆盖为平台项目 ID,无需传递
ipFilter 否 IpFilter IP 黑白名单配置
ipFreqLimit 否 IpFreqLimit IP 限频配置
statusCodeCache 否 StatusCodeCache 状态码缓存配置
compression 否 Compression 智能压缩配置
bandwidthAlert 否 BandwidthAlert 带宽封顶配置
rangeOriginPull 否 RangeOriginPull Range 回源配置
followRedirect 否 FollowRedirect 301/302 回源跟随配置
errorPage 否 ErrorPage 错误码重定向配置(功能灰度中)
requestHeader 否 RequestHeader 回源请求头配置
responseHeader 否 ResponseHeader 响应头配置
downstreamCapping 否 DownstreamCapping 下载速度配置
cacheKey 否 CacheKey 节点缓存键配置
responseHeaderCache 否 ResponseHeaderCache 头部缓存配置
videoSeek 否 VideoSeek 视频拖拽配置
cache 否 Cache 缓存过期时间配置
originPullOptimization 否 OriginPullOptimization 跨国链路优化配置(已下线)
https 否 Https HTTPS 加速配置
authentication 否 Authentication 时间戳防盗链配置
seo 否 Seo SEO 优化配置
forceRedirect 否 ForceRedirect 访问协议强制跳转配置
referer 否 Referer Referer 防盗链配置
maxAge 否 MaxAge 浏览器缓存配置(功能灰度中)
ipv6 否 Ipv6 IPv6 回源配置(功能灰度中)
specificConfig 否 SpecificConfig 境内、境外加速配置不一致时的地域特殊配置
originPullTimeout 否 OriginPullTimeout 回源超时配置
tag 否 [Tag] 上游标签配置。平台资源标签请使用请求体中的 tags
ipv6Access 否 Ipv6Access IPv6 访问配置
offlineCache 否 OfflineCache 离线缓存
quic 否 Quic QUIC 访问(收费服务)
awsPrivateAccess 否 AwsPrivateAccess 回源 S3 私有鉴权
ossPrivateAccess 否 OssPrivateAccess 回源 OSS 私有鉴权
hwPrivateAccess 否 HwPrivateAccess 华为云对象存储回源鉴权
qnPrivateAccess 否 QnPrivateAccess 七牛云对象存储回源鉴权
othersPrivateAccess 否 OthersPrivateAccess 其他厂商对象存储回源鉴权
httpsBilling 否 HttpsBilling HTTPS 服务。缺省时默认开启(收费服务)

Tag

上游标签。平台侧绑定请使用请求体顶层的 tags。

参数名称 必选 类型 描述
tagKey 是 String 标签键。示例值:env
tagValue 是 String 标签值。示例值:prod

ResponseMetadata

创建结果。

参数名称 类型 描述
errorCode String 结果码。success 表示成功,否则为上游错误码。示例值:success
errorMessage String 失败原因。成功时为空字符串