跳转至

新建或修改源站组

1. 接口描述

接口请求路径:POST /prod-api/multiCdn/origin/modifyOriginGroup

modifyOriginGroup 用于新建或修改源站组。省略 originGroupGrnId 时新建,传入时更新该源站组的名称和源站记录。每个源站组只能保存 1 条源站记录;保存时会先删除原有记录再写入本次提交的记录。源站组已关联域名时,保存成功后会为这些域名创建更新部署任务。账号需具备 cdn2:EditDomain 权限。

Token 获取方式见 密钥鉴权。

说明:本接口返回的 originGroupGrnId 按当前用户 ID 拼接。查询接口按源站组所属账号拼接。后续修改、删除请使用 查询源站组列表 返回的 ID。

2. 输入参数

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

参数名称 必选 类型 描述
originGroupName 是 String 源站组名称。只能包含字母、数字、下划线、连字符。示例值:origin-demo
originRecords 是 Array of OriginRecords 源站记录,只能有 1 条
originGroupGrnId 否 String 源站组 ID。传入时更新该源站组。示例值:grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461

3. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:成功
data Object 保存后的源站组
data.originGroupGrnId String 源站组 ID。示例值:grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461
data.originGroupName String 源站组名称。示例值:origin-demo
data.originRecords Array of OriginRecords 本次提交的源站记录

4. 示例

示例1 新建源站组

输入示例

{
  "originGroupName": "origin-demo",
  "originRecords": [
    {
      "record": "origin.demo.com",
      "weight": 100
    }
  ]
}

代码调用

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

curl -X POST 'https://{登录域名}/prod-api/multiCdn/origin/modifyOriginGroup' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "originGroupName": "origin-demo",
  "originRecords": [
    {
      "record": "origin.demo.com",
      "weight": 100
    }
  ]
}'
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 ModifyOriginGroupTest {

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

        String requestBody = "{"
                + "\"originGroupName\":\"origin-demo\","
                + "\"originRecords\":[{"
                + "\"record\":\"origin.demo.com\","
                + "\"weight\":100"
                + "}]"
                + "}";

        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/multiCdn/origin/modifyOriginGroup"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "originGroupName": "origin-demo",
  "originRecords": [
    {
      "record": "origin.demo.com",
      "weight": 100
    }
  ]
}`)

    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))
}

输出示例

{
  "code": 200,
  "msg": "成功",
  "data": {
    "originGroupGrnId": "grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461",
    "originGroupName": "origin-demo",
    "originRecords": [
      {
        "record": "origin.demo.com",
        "weight": 100
      }
    ]
  }
}

示例2 修改已有源站组

输入示例

{
  "originGroupGrnId": "grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461",
  "originGroupName": "origin-demo",
  "originRecords": [
    {
      "record": "10.0.0.8",
      "weight": null
    }
  ]
}

代码调用

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

curl -X POST 'https://{登录域名}/prod-api/multiCdn/origin/modifyOriginGroup' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "originGroupGrnId": "grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461",
  "originGroupName": "origin-demo",
  "originRecords": [
    {
      "record": "10.0.0.8",
      "weight": null
    }
  ]
}'
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 ModifyOriginGroupTest {

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

        String requestBody = "{"
                + "\"originGroupGrnId\":\"grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461\","
                + "\"originGroupName\":\"origin-demo\","
                + "\"originRecords\":[{"
                + "\"record\":\"10.0.0.8\","
                + "\"weight\":null"
                + "}]"
                + "}";

        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/multiCdn/origin/modifyOriginGroup"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "originGroupGrnId": "grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461",
  "originGroupName": "origin-demo",
  "originRecords": [
    {
      "record": "10.0.0.8",
      "weight": null
    }
  ]
}`)

    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))
}

输出示例

{
  "code": 200,
  "msg": "成功",
  "data": {
    "originGroupGrnId": "grn:test:multi-cdn:001:origin/174c12cc214bf7d0020fc48461",
    "originGroupName": "origin-demo",
    "originRecords": [
      {
        "record": "10.0.0.8",
        "weight": null
      }
    ]
  }
}

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
源站组不能为空 未传 originRecords,或源站记录为空
源站组名只能为a-z, A-Z, 0-9, _, - originGroupName 含有字母、数字、下划线、连字符以外的字符
源站地址只能有一个源站 originRecords 超过 1 条
源站组权重只能为1-100 已填写 weight,且不在 1-100

6. 数据模型

OriginRecords

保存源站组时提交的源站记录。

参数名称 必选 类型 描述
record 是 String 源站地址,可为 IPv4 或域名。示例值:origin.demo.com
weight 否 Integer 权重。取值范围:1-100。示例值:100
recordId 否 String 源站记录 ID。保存时不读取该字段