跳转至

批量创建域名

1. 接口描述

接口请求路径:POST /prod-api/cdn/domain/batchCreateDomain

batchCreateDomain 用于批量创建安全加速域名,单次最多 100 个。请求整体校验通过后按域名逐条创建:部分域名失败时接口仍可能返回 HTTP 200,请根据 data[].error 判断每一条的结果。

Token 获取方式见 密钥鉴权

注意port80443 或小于 0 时,服务端会按 0 处理。port 规范化后大于 0 时,origin.httpOriginPortorigin.httpsOriginPort 必须相同。

2. 输入参数

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

参数名称 必选 类型 描述
domainNames Array of String 待创建域名,非空、不可重复,最多 100 个。示例值:["demotest.com"]
oid String 当前账号下未过期的七层套餐号。示例值:202405232795134123456
port Integer 访问端口。80443 或小于 0 时按 0 处理。示例值:0
customerRemark String 备注
resouceHost String 回源 Host,默认 HOST 时传空字符串
upstream Integer 负载均衡。取值:0(轮询)、2(会话保持)。默认值:2。示例值:2
webSocket Integer WebSocket。取值:0(关闭)、1(开启)。默认值:0。示例值:1
filterParameters Integer 过滤参数。取值:0(关闭)、1(开启)。默认值:0。示例值:0
rangeSource Integer 分片回源。取值:0(关闭)、1(开启)。默认值:0。示例值:0
locationList [SaveDomainLocation] 缓存过期设置,不传或空数组表示不配置
origin DomainOrigin 源站配置
webFenceConfig webFenceConfig 安全策略关联,不传或 {} 表示不关联
certId Long 已有证书 ID,不传或 0 时不绑定

3. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:成功
data Array of Object 逐条创建结果,顺序与请求中的 domainNames 对应
data[].domainName String 域名。示例值:demotest.com
data[].port Integer 规范化后的访问端口。示例值:0
data[].error String 该条失败原因;成功时为 null。示例值:null

4. 示例

示例1 批量创建域名(源站组)

输入示例

{
  "domainNames": ["demotest.com"],
  "port": 0,
  "oid": "202405232795134123456",
  "customerRemark": "",
  "resouceHost": "",
  "upstream": 2,
  "webSocket": 1,
  "locationList": [
    {
      "locationValue": "/",
      "locationType": 1,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    },
    {
      "locationValue": "js;css;eot;svg;ttf;woff;otf",
      "locationType": 2,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    },
    {
      "locationValue": "png;jpg;jpeg;gif;ico;bmp",
      "locationType": 2,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    }
  ],
  "filterParameters": 0,
  "rangeSource": 0,
  "origin": {
    "httpOriginPort": 80,
    "httpsOriginPort": 443,
    "originGroupId": 1338,
    "originRecord": "",
    "originType": "originGroup",
    "originProtocol": 0
  }
}

代码调用

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

curl -X POST 'https://{登录域名}/prod-api/cdn/domain/batchCreateDomain' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "domainNames": ["demotest.com"],
  "port": 0,
  "oid": "202405232795134123456",
  "customerRemark": "",
  "resouceHost": "",
  "upstream": 2,
  "webSocket": 1,
  "locationList": [
    {
      "locationValue": "/",
      "locationType": 1,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    },
    {
      "locationValue": "js;css;eot;svg;ttf;woff;otf",
      "locationType": 2,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    },
    {
      "locationValue": "png;jpg;jpeg;gif;ico;bmp",
      "locationType": 2,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    }
  ],
  "filterParameters": 0,
  "rangeSource": 0,
  "origin": {
    "httpOriginPort": 80,
    "httpsOriginPort": 443,
    "originGroupId": 1338,
    "originRecord": "",
    "originType": "originGroup",
    "originProtocol": 0
  }
}'
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 BatchCreateDomainTest {

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

        String requestBody = "{"
                + "\"domainNames\":[\"demotest.com\"],"
                + "\"port\":0,"
                + "\"oid\":\"202405232795134123456\","
                + "\"customerRemark\":\"\","
                + "\"resouceHost\":\"\","
                + "\"upstream\":2,"
                + "\"webSocket\":1,"
                + "\"locationList\":["
                + "{\"locationValue\":\"/\",\"locationType\":1,\"cacheTime\":0,\"cacheParameter\":0,\"cacheTimeUnit\":\"s\"},"
                + "{\"locationValue\":\"js;css;eot;svg;ttf;woff;otf\",\"locationType\":2,\"cacheTime\":0,\"cacheParameter\":0,\"cacheTimeUnit\":\"s\"},"
                + "{\"locationValue\":\"png;jpg;jpeg;gif;ico;bmp\",\"locationType\":2,\"cacheTime\":0,\"cacheParameter\":0,\"cacheTimeUnit\":\"s\"}"
                + "],"
                + "\"filterParameters\":0,"
                + "\"rangeSource\":0,"
                + "\"origin\":{"
                + "\"httpOriginPort\":80,"
                + "\"httpsOriginPort\":443,"
                + "\"originGroupId\":1338,"
                + "\"originRecord\":\"\","
                + "\"originType\":\"originGroup\","
                + "\"originProtocol\":0"
                + "}"
                + "}";

        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/cdn/domain/batchCreateDomain"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "domainNames": ["demotest.com"],
  "port": 0,
  "oid": "202405232795134123456",
  "customerRemark": "",
  "resouceHost": "",
  "upstream": 2,
  "webSocket": 1,
  "locationList": [
    {
      "locationValue": "/",
      "locationType": 1,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    },
    {
      "locationValue": "js;css;eot;svg;ttf;woff;otf",
      "locationType": 2,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    },
    {
      "locationValue": "png;jpg;jpeg;gif;ico;bmp",
      "locationType": 2,
      "cacheTime": 0,
      "cacheParameter": 0,
      "cacheTimeUnit": "s"
    }
  ],
  "filterParameters": 0,
  "rangeSource": 0,
  "origin": {
    "httpOriginPort": 80,
    "httpsOriginPort": 443,
    "originGroupId": 1338,
    "originRecord": "",
    "originType": "originGroup",
    "originProtocol": 0
  }
}`)

    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": [
    {
      "domainName": "demotest.com",
      "port": 0,
      "error": null
    }
  ]
}

5. 错误码

以下为接口在整体校验失败时返回的业务提示(中文环境)。逐条创建阶段的失败写在 data[].error 中,不一定改变 HTTP 状态码。

HTTP 状态码 / 业务提示 描述
200 已受理,请检查 data[].error
401 未鉴权或 Token 无效
403 无权限
缺少必填字段:请填写端口。 未传 port
缺少必填字段:请填写域名。 未传 domainNames,或为空/含空串
缺少必填来源:请填写必填来源。 未传 origin
分片回源 rangeSource 取值无效:取值:0(关闭)、1(开启)。 rangeSource 不是 01
参数过滤filterParameters取值无效:取值:0(关闭)、1(开启)。 filterParameters 不是 01
超过最大域名限制:您一次最多只能上传100个域名。 domainNames 超过 100 个
无效的套餐ID:请输入有效的套餐ID。 套餐不存在或不属于当前账号
套餐已过期,无法继续添加域名。 所属套餐已过期
该套餐可使用域名不足。 本次数量超过剩余配额
该套餐可使用域名已达上限。 ({0}/{1}) 写入中达上限,{0} 已用 / {1} 上限
输入的域名中存在重复的域名。 domainNames 有重复项
添加失败:The value of the cached object exceeds the maximum length locationValue 长度超过 150
域名格式无效:请填写有效的域名,错误域名:{0}。 域名格式非法
域名无法重复添加:域名[{0}],无法添加到该套餐中。可能原因:1.当前资源池中已存在该域名。 同项目下该域名与端口已存在
回源端口无效:特殊域名端口情况下,回源端口需一致。 port > 0 时 HTTP/HTTPS 回源端口不一致
回源地址不能为空 origin 为空
回源类型只能为ipDomain或originGroup originType 不合法
回源类型为ipDomain时,回源地址不能为空且只能为IP ipDomainoriginRecord 不是 IPv4
回源类型为originGroup时,回源组不能为空 originGroup 时未传合法 originGroupId
源站组不存在,请确认源站组ID是否正确 originGroupId 对应源站组不存在
回源端口不能为空且范围在1-65535之间 回源端口为空或不在 1–65535
回源协议originProtocol取值无效:取值:0(HTTP)、1(协议跟随)、2(HTTPS)。 originProtocol 不是 012
添加完成:等待审核中 data[].error:该条未进入成功状态
添加失败:{0} data[].error:该条创建异常,{0} 为原因
添加完成:{0} data[].error:事务已提交后的异常说明
套餐可使用顶级域名不足,请升级套餐或删除部分域名后再试 data[].error:顶级域名配额不足
添加失败 data[].error:写入域名记录失败
提交失败:无效的托管证书ID data[].errorcertId 无效
提交失败:域名与证书不匹配! data[].error:证书与域名不匹配

6. 数据模型

SaveDomainLocation

缓存过期设置项。

参数名称 必选 类型 描述
locationValue String 匹配内容,最长 150。目录如 /,文件类型如 js;css。示例值:/
locationType Integer 类型。取值:1(全部)、2(文件类型)、3(文件夹)、4(全路径)。示例值:1
cacheTime Integer 缓存时间。示例值:0
cacheTimeUnit String 缓存时间单位,如 s。示例值:s
cacheParameter Integer 过滤参数。示例值:0

DomainOrigin

源站配置。

参数名称 必选 类型 描述
originType String 源站类型。取值:ipDomain(IP)、originGroup(源站组)。示例值:originGroup
originRecord String 源站 IPv4,originTypeipDomain 时必填
originGroupId Long 源站组 ID,originTypeoriginGroup 时必填且不能小于 0。示例值:1338
originProtocol Integer 回源协议。取值:0(HTTP)、1(协议跟随)、2(HTTPS)。示例值:0
httpOriginPort Integer HTTP 回源端口,1–65535。示例值:80
httpsOriginPort Integer HTTPS 回源端口,1–65535;port > 0 时须与 HTTP 回源端口一致。示例值:443

webFenceConfig

安全策略关联配置。字段类型为数值,请传整数或省略字段,不要传空字符串。

参数名称 必选 类型 描述
wafId Long Web 应用防火墙 3.0 策略 ID
httpDdosId Long HTTP DDoS 策略 ID