{
  "tags": [
    "证书管理"
  ],
  "description": "创建一个或多个证书记录；请求体可以是单个 JSON 对象，也可以是对象数组，数组中的全部证书在同一个数据库事务中处理。普通用户证书归属于当前账号，管理员可以通过 `uid` 指定所属用户。`custom` 表示上传已有证书和私钥，`lets`、`zerossl`、`buypass` 表示自动签发；自动签发证书创建后会立即建立签发任务。任一证书校验失败时整个批次回滚，不会保留已插入的部分记录。",
  "operationId": "user_post_v1_certs",
  "security": [
    {
      "AccessToken": []
    },
    {
      "ApiKey": [],
      "ApiSecret": []
    }
  ],
  "responses": {
    "200": {
      "description": "业务结果通过 HTTP 200 返回。全部证书校验并提交后返回创建结果；配额、套餐、名称、类型、DNS API、域名、PEM、管理员归属、证书有效性、参数状态、兼容性更新字段、系统维护或认证校验失败时返回字符串业务错误码，整个批次事务回滚。",
      "content": {
        "application/json": {
          "schema": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "integer",
                    "enum": [
                      0
                    ],
                    "description": "成功状态码，所有证书创建并提交后固定为 0。"
                  },
                  "msg": {
                    "type": "string",
                    "enum": [
                      "证书添加成功"
                    ],
                    "description": "证书创建批次成功后返回的确认消息。"
                  },
                  "data": {
                    "type": "string",
                    "description": "正常创建时为新证书 ID 的英文逗号分隔字符串；空数组时为空字符串。若兼容性地传入 `id` 触发更新逻辑，内容可能是更新差异 JSON 字符串。"
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "required": [
                  "code",
                  "msg",
                  "data"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "enum": [
                      "cert-6",
                      "cert-7",
                      "cert-8",
                      "cert-9",
                      "cert-11",
                      "cert-12",
                      "cert-14",
                      "cert-15",
                      "cert-17",
                      "cert-18",
                      "cert-19",
                      "cert-21",
                      "cert-22",
                      "cert-23",
                      "cert-25",
                      "cert-26",
                      "cert-27",
                      "cert-28",
                      "cert-29",
                      "cert-30",
                      "cert-31",
                      "cert-32",
                      "cert-38",
                      "cert-39",
                      "cert-40",
                      "cert-41",
                      "cert-42",
                      "cert-43",
                      "cert-45",
                      "cert-46",
                      "cert-48",
                      "cert-49",
                      "maintain",
                      "login_required"
                    ],
                    "description": "业务错误码：6、7 表示兼容性 ID 格式错误或记录不存在；8、23 表示证书数量超限或普通用户未购买有效套餐；9、11、12 表示名称为空、重复或缺失；14、15 表示证书类型为空或无效；17、18 表示 DNS API 格式错误或不存在；19、21、22 表示自动证书域名为空、通配符缺少 DNS API 或域名未提供；25、26、27、28、29、40、41、43、46 表示私钥/证书缺失、格式、解析、匹配或域名提取失败；30、31、42、45 表示启用、自动续签或强制禁用参数无效；32 表示证书仍被网站使用且未强制禁用；38、39 表示重新签发仅支持已有自动证书或不能在创建时使用；48、49 表示管理员专属归属字段或目标证书权限不足；`maintain` 表示当前禁止写操作，`login_required` 表示认证无效。"
                  },
                  "msg": {
                    "type": "string",
                    "description": "与业务错误码对应的中文配额、套餐、字段、证书材料、权限、任务状态、维护状态或认证失败原因。"
                  },
                  "data": {
                    "type": "string",
                    "enum": [
                      ""
                    ],
                    "description": "业务错误时固定为空字符串。"
                  }
                },
                "additionalProperties": false
              }
            ]
          },
          "example": {
            "code": 0,
            "msg": "证书添加成功",
            "data": "10021,10022"
          }
        }
      }
    }
  },
  "x-python-handler": "site.CertAPI",
  "x-python-route-line": 362,
  "x-audience": "user",
  "x-auth": "user",
  "x-reviewed": true,
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "name"
              ],
              "properties": {
                "uid": {
                  "type": "integer",
                  "format": "int64",
                  "minimum": 1,
                  "description": "证书所属用户 ID；省略时使用当前登录用户，仅管理员可指定，否则返回 `cert-48`。"
                },
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 255,
                  "description": "证书显示名称；服务端会过滤可执行的 HTML，处理后不得为空，同一所属用户下不可重复，并只保存处理后前 200 个字符。创建时必填。"
                },
                "des": {
                  "type": "string",
                  "maxLength": 255,
                  "description": "证书备注；服务端会过滤可执行的 HTML，省略时保存为空字符串。"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "custom",
                    "lets",
                    "zerossl",
                    "buypass"
                  ],
                  "description": "证书类型：`custom` 为上传证书，`lets` 为 Let's Encrypt，`zerossl` 为 ZeroSSL，`buypass` 为 BuyPass。省略时读取全局或用户证书默认配置。"
                },
                "dnsapi": {
                  "oneOf": [
                    {
                      "type": "integer",
                      "minimum": 1
                    },
                    {
                      "type": "string",
                      "pattern": "^[0-9]+$"
                    },
                    {
                      "type": "string",
                      "nullable": true,
                      "enum": [
                        null
                      ]
                    }
                  ],
                  "description": "自动签发所使用的 DNS API 配置 ID；可显式传 null 表示不使用，非空时必须是已存在的 DNS API。通配符自动证书必须指定非空 DNS API。省略时读取用户默认配置。"
                },
                "domain": {
                  "type": "string",
                  "description": "自动签发证书的域名，类型为 `lets`、`zerossl` 或 `buypass` 时必填并会转为小写；通配符域名还必须配合 DNS API。`custom` 类型不会采用该字段，而是从证书的 SAN/CN 中解析域名。"
                },
                "key": {
                  "type": "string",
                  "format": "password",
                  "writeOnly": true,
                  "description": "上传证书的私钥 PEM；`custom` 类型必填，服务端会去除首尾空白、校验末尾 PEM 分隔符并验证与证书匹配。其他类型通常省略。示例不得填入真实私钥。"
                },
                "cert": {
                  "type": "string",
                  "writeOnly": true,
                  "description": "上传证书链 PEM；`custom` 类型必填，服务端会解析每个证书并验证有效性。其他类型通常省略。示例不得填入真实证书内容。"
                }
              },
              "additionalProperties": true,
              "description": "单个证书创建对象。普通创建至少需要 `name`；证书类型及其条件字段由服务端按上述规则校验。"
            },
            {
              "type": "array",
              "minItems": 0,
              "description": "批量证书创建对象数组；数组可以为空，空数组会提交一个不含证书的空批次并返回空数据字符串。数组中任一对象校验失败时整批回滚。",
              "items": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "uid": {
                    "type": "integer",
                    "format": "int64",
                    "minimum": 1,
                    "description": "证书所属用户 ID；省略时使用当前登录用户，仅管理员可指定，否则返回 `cert-48`。"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "证书显示名称；服务端会过滤可执行的 HTML，处理后不得为空，同一所属用户下不可重复，并只保存处理后前 200 个字符。创建时必填。"
                  },
                  "des": {
                    "type": "string",
                    "maxLength": 255,
                    "description": "证书备注；服务端会过滤可执行的 HTML，省略时保存为空字符串。"
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "custom",
                      "lets",
                      "zerossl",
                      "buypass"
                    ],
                    "description": "证书类型：`custom` 为上传证书，`lets` 为 Let's Encrypt，`zerossl` 为 ZeroSSL，`buypass` 为 BuyPass。省略时读取全局或用户证书默认配置。"
                  },
                  "dnsapi": {
                    "oneOf": [
                      {
                        "type": "integer",
                        "minimum": 1
                      },
                      {
                        "type": "string",
                        "pattern": "^[0-9]+$"
                      },
                      {
                        "type": "string",
                        "nullable": true,
                        "enum": [
                          null
                        ]
                      }
                    ],
                    "description": "自动签发所使用的 DNS API 配置 ID；可显式传 null 表示不使用，非空时必须是已存在的 DNS API。通配符自动证书必须指定非空 DNS API。省略时读取用户默认配置。"
                  },
                  "domain": {
                    "type": "string",
                    "description": "自动签发证书的域名，类型为 `lets`、`zerossl` 或 `buypass` 时必填并会转为小写；通配符域名还必须配合 DNS API。`custom` 类型不会采用该字段，而是从证书的 SAN/CN 中解析域名。"
                  },
                  "key": {
                    "type": "string",
                    "format": "password",
                    "writeOnly": true,
                    "description": "上传证书的私钥 PEM；`custom` 类型必填，服务端会去除首尾空白、校验末尾 PEM 分隔符并验证与证书匹配。其他类型通常省略。示例不得填入真实私钥。"
                  },
                  "cert": {
                    "type": "string",
                    "writeOnly": true,
                    "description": "上传证书链 PEM；`custom` 类型必填，服务端会解析每个证书并验证有效性。其他类型通常省略。示例不得填入真实证书内容。"
                  }
                },
                "additionalProperties": true,
                "description": "单个证书创建对象。普通创建至少需要 `name`；证书类型及其条件字段由服务端按上述规则校验。"
              }
            }
          ]
        },
        "example": {
          "name": "API 自动证书",
          "des": "生产站点证书",
          "type": "lets",
          "domain": "api.example.invalid",
          "dnsapi": 12
        }
      }
    }
  },
  "parameters": [],
  "x-itecdn-source-reviewed": true,
  "extensions": [
    {
      "key": "x-python-handler",
      "value": "site.CertAPI"
    },
    {
      "key": "x-python-route-line",
      "value": 362
    },
    {
      "key": "x-audience",
      "value": "user"
    },
    {
      "key": "x-auth",
      "value": "user"
    },
    {
      "key": "x-reviewed",
      "value": true
    },
    {
      "key": "x-itecdn-source-reviewed",
      "value": true
    }
  ],
  "method": "post",
  "path": "/v1/certs",
  "servers": [
    {
      "url": "https://master.example.invalid",
      "description": "不可调用的示例地址；复制示例后替换为自己的主控域名。"
    }
  ],
  "securitySchemes": {
    "AccessToken": {
      "type": "apiKey",
      "in": "header",
      "name": "access-token",
      "description": "通过登录接口获得的短期访问令牌。"
    },
    "ApiKey": {
      "type": "apiKey",
      "in": "header",
      "name": "api-key",
      "description": "API Key；必须和 api-secret 同时发送。"
    },
    "ApiSecret": {
      "type": "apiKey",
      "in": "header",
      "name": "api-secret",
      "description": "API Secret；必须和 api-key 同时发送。"
    }
  },
  "jsonRequestBodyExample": {
    "uid": 0,
    "name": "string",
    "des": "string",
    "type": "custom",
    "dnsapi": 0,
    "domain": "string",
    "key": "string",
    "cert": "string"
  },
  "info": {
    "title": "itecdn v5 用户 API",
    "version": "5.x",
    "description": "itecdn v5.x Python 主控用户 API。本文档不适用于 v6 或其它实现。"
  },
  "postman": {
    "name": "添加一个或多个证书",
    "description": {
      "content": "创建一个或多个证书记录；请求体可以是单个 JSON 对象，也可以是对象数组，数组中的全部证书在同一个数据库事务中处理。普通用户证书归属于当前账号，管理员可以通过 `uid` 指定所属用户。`custom` 表示上传已有证书和私钥，`lets`、`zerossl`、`buypass` 表示自动签发；自动签发证书创建后会立即建立签发任务。任一证书校验失败时整个批次回滚，不会保留已插入的部分记录。",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "v1",
        "certs"
      ],
      "host": [
        "{{baseUrl}}"
      ],
      "query": [],
      "variable": []
    },
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "method": "POST",
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "auth": {
      "type": "apikey",
      "apikey": [
        {
          "type": "any",
          "value": "access-token",
          "key": "key"
        },
        {
          "type": "any",
          "value": "{{apiKey}}",
          "key": "value"
        },
        {
          "type": "any",
          "value": "header",
          "key": "in"
        }
      ]
    }
  }
}