{
  "tags": [
    "四层转发"
  ],
  "description": "创建一个或多个四层转发。请求体可以是单个对象或对象数组；每项均必须指定用户套餐、监听配置、回源端口和源站列表。未指定的协议、负载方式和 PROXY protocol 使用当前区域及用户默认配置。管理员可额外指定用户、区域、线路和 CNAME 资源。",
  "operationId": "user_post_v1_streams",
  "security": [
    {
      "AccessToken": []
    },
    {
      "ApiKey": [],
      "ApiSecret": []
    }
  ],
  "responses": {
    "200": {
      "description": "请求已被处理。成功时 `code` 为 0、`msg` 为“四层转发添加成功”、`data` 为新建转发 ID 的逗号分隔字符串；业务校验失败仍返回 HTTP 200。",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "code",
              "msg",
              "data"
            ],
            "properties": {
              "code": {
                "type": "integer",
                "description": "业务状态码；成功为 0。",
                "example": 0
              },
              "msg": {
                "type": "string",
                "description": "处理结果说明。",
                "example": "四层转发添加成功"
              },
              "data": {
                "type": "string",
                "description": "成功时的新建转发 ID，多个 ID 用英文逗号分隔；失败时为空字符串。",
                "example": "101,102"
              }
            }
          },
          "examples": {
            "success": {
              "summary": "创建成功",
              "value": {
                "code": 0,
                "msg": "四层转发添加成功",
                "data": "101"
              }
            },
            "missingListen": {
              "summary": "缺少监听",
              "value": {
                "code": "stream-26",
                "msg": "listen不能为空",
                "data": ""
              }
            }
          },
          "example": {
            "code": 0,
            "msg": "四层转发添加成功",
            "data": "101"
          }
        }
      }
    }
  },
  "x-python-handler": "stream.StreamAPI",
  "x-python-route-line": 637,
  "x-audience": "user",
  "x-auth": "user",
  "x-reviewed": true,
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "user_package",
                "listen",
                "backend_port",
                "backend"
              ],
              "properties": {
                "user_package": {
                  "type": "integer",
                  "minimum": 1,
                  "description": "必填。用户套餐 ID；套餐须存在、可用且属于当前用户。"
                },
                "listen": {
                  "type": "array",
                  "minItems": 1,
                  "description": "必填。监听列表；端口必须在所在区域允许范围内且未占用。",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "port"
                    ],
                    "properties": {
                      "port": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 65535,
                        "description": "必填。监听端口。"
                      },
                      "protocol": {
                        "type": "string",
                        "enum": [
                          "tcp",
                          "udp"
                        ],
                        "description": "监听协议；创建时省略则使用默认协议。"
                      }
                    }
                  }
                },
                "backend_port": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 65535,
                  "description": "必填。源站回源端口。"
                },
                "backend": {
                  "type": "array",
                  "minItems": 1,
                  "description": "必填。源站列表，至少有一个状态为 `up` 的源站。",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "addr"
                    ],
                    "properties": {
                      "addr": {
                        "type": "string",
                        "description": "必填。源站 IPv4、IPv6 或域名，不能是系统节点 IP。"
                      },
                      "weight": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 10,
                        "description": "源站权重；创建时省略为 1。"
                      },
                      "state": {
                        "type": "string",
                        "enum": [
                          "up",
                          "down",
                          "backup"
                        ],
                        "description": "源站状态；创建时省略为 `up`。`ip_hash` 不支持备用源站。"
                      }
                    }
                  }
                },
                "balance_way": {
                  "type": "string",
                  "enum": [
                    "ip_hash",
                    "rr"
                  ],
                  "description": "负载均衡方式；省略时使用默认配置。"
                },
                "proxy_protocol": {
                  "type": "integer",
                  "enum": [
                    0,
                    1
                  ],
                  "description": "是否向源站发送 PROXY protocol；省略时使用默认配置。"
                },
                "conn_limit": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "连接数限制；可为空。"
                },
                "acl": {
                  "type": "object",
                  "description": "访问控制配置。",
                  "additionalProperties": false,
                  "properties": {
                    "enable": {
                      "type": "integer",
                      "enum": [
                        0,
                        1
                      ],
                      "description": "是否启用 ACL。"
                    }
                  }
                },
                "block_region": {
                  "type": "string",
                  "description": "地域拦截配置。"
                },
                "des": {
                  "type": "string",
                  "description": "转发备注；会进行 XSS 过滤，可为空。"
                },
                "enable": {
                  "type": "integer",
                  "enum": [
                    0,
                    1
                  ],
                  "description": "是否启用转发。"
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "200",
                    "512",
                    "513",
                    "514"
                  ],
                  "description": "管理员专用。四层转发业务状态：200 正常、512 套餐到期、513 流量超限、514 锁定；创建时省略则为 200。",
                  "default": "200"
                },
                "groups": {
                  "type": "string",
                  "description": "应用用户默认配置和关联转发组的 ID 列表，使用英文逗号分隔。"
                },
                "uid": {
                  "type": "integer",
                  "description": "管理员专用。指定归属用户 ID。"
                },
                "cname_domain": {
                  "type": "integer",
                  "description": "管理员专用。CNAME 域名配置 ID。"
                },
                "cname_mode": {
                  "type": "string",
                  "enum": [
                    "package",
                    "site"
                  ],
                  "description": "管理员专用。CNAME 使用方式。"
                },
                "cname_hostname": {
                  "type": "string",
                  "description": "管理员专用。CNAME 主机名。"
                },
                "region_id": {
                  "type": "integer",
                  "description": "管理员专用。区域 ID。"
                },
                "node_group_id": {
                  "type": "integer",
                  "description": "管理员专用。主线路组 ID。"
                },
                "backup_node_group": {
                  "type": "integer",
                  "nullable": true,
                  "description": "管理员专用。备用线路组 ID。"
                },
                "enable_ipv6": {
                  "type": "integer",
                  "enum": [
                    0,
                    1
                  ],
                  "description": "是否启用 IPv6。"
                }
              }
            },
            {
              "type": "array",
              "minItems": 1,
              "description": "批量创建；每一项字段与单对象创建相同。",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "user_package",
                  "listen",
                  "backend_port",
                  "backend"
                ],
                "properties": {
                  "user_package": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "必填。用户套餐 ID；套餐须存在、可用且属于当前用户。"
                  },
                  "listen": {
                    "type": "array",
                    "minItems": 1,
                    "description": "必填。监听列表；端口必须在所在区域允许范围内且未占用。",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "port"
                      ],
                      "properties": {
                        "port": {
                          "type": "integer",
                          "minimum": 1,
                          "maximum": 65535,
                          "description": "必填。监听端口。"
                        },
                        "protocol": {
                          "type": "string",
                          "enum": [
                            "tcp",
                            "udp"
                          ],
                          "description": "监听协议；创建时省略则使用默认协议。"
                        }
                      }
                    }
                  },
                  "backend_port": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 65535,
                    "description": "必填。源站回源端口。"
                  },
                  "backend": {
                    "type": "array",
                    "minItems": 1,
                    "description": "必填。源站列表，至少有一个状态为 `up` 的源站。",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "addr"
                      ],
                      "properties": {
                        "addr": {
                          "type": "string",
                          "description": "必填。源站 IPv4、IPv6 或域名，不能是系统节点 IP。"
                        },
                        "weight": {
                          "type": "integer",
                          "minimum": 1,
                          "maximum": 10,
                          "description": "源站权重；创建时省略为 1。"
                        },
                        "state": {
                          "type": "string",
                          "enum": [
                            "up",
                            "down",
                            "backup"
                          ],
                          "description": "源站状态；创建时省略为 `up`。`ip_hash` 不支持备用源站。"
                        }
                      }
                    }
                  },
                  "balance_way": {
                    "type": "string",
                    "enum": [
                      "ip_hash",
                      "rr"
                    ],
                    "description": "负载均衡方式；省略时使用默认配置。"
                  },
                  "proxy_protocol": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ],
                    "description": "是否向源站发送 PROXY protocol；省略时使用默认配置。"
                  },
                  "conn_limit": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "连接数限制；可为空。"
                  },
                  "acl": {
                    "type": "object",
                    "description": "访问控制配置。",
                    "additionalProperties": false,
                    "properties": {
                      "enable": {
                        "type": "integer",
                        "enum": [
                          0,
                          1
                        ],
                        "description": "是否启用 ACL。"
                      }
                    }
                  },
                  "block_region": {
                    "type": "string",
                    "description": "地域拦截配置。"
                  },
                  "des": {
                    "type": "string",
                    "description": "转发备注；会进行 XSS 过滤，可为空。"
                  },
                  "enable": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ],
                    "description": "是否启用转发。"
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "200",
                      "512",
                      "513",
                      "514"
                    ],
                    "description": "管理员专用。四层转发业务状态：200 正常、512 套餐到期、513 流量超限、514 锁定；创建时省略则为 200。",
                    "default": "200"
                  },
                  "groups": {
                    "type": "string",
                    "description": "应用用户默认配置和关联转发组的 ID 列表，使用英文逗号分隔。"
                  },
                  "uid": {
                    "type": "integer",
                    "description": "管理员专用。指定归属用户 ID。"
                  },
                  "cname_domain": {
                    "type": "integer",
                    "description": "管理员专用。CNAME 域名配置 ID。"
                  },
                  "cname_mode": {
                    "type": "string",
                    "enum": [
                      "package",
                      "site"
                    ],
                    "description": "管理员专用。CNAME 使用方式。"
                  },
                  "cname_hostname": {
                    "type": "string",
                    "description": "管理员专用。CNAME 主机名。"
                  },
                  "region_id": {
                    "type": "integer",
                    "description": "管理员专用。区域 ID。"
                  },
                  "node_group_id": {
                    "type": "integer",
                    "description": "管理员专用。主线路组 ID。"
                  },
                  "backup_node_group": {
                    "type": "integer",
                    "nullable": true,
                    "description": "管理员专用。备用线路组 ID。"
                  },
                  "enable_ipv6": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ],
                    "description": "是否启用 IPv6。"
                  }
                }
              }
            }
          ],
          "example": {
            "user_package": 8,
            "listen": [
              {
                "port": 443,
                "protocol": "tcp"
              }
            ],
            "backend_port": 443,
            "backend": [
              {
                "addr": "198.51.100.10",
                "weight": 1,
                "state": "up"
              }
            ]
          }
        }
      }
    }
  },
  "parameters": [],
  "x-itecdn-source-reviewed": true,
  "extensions": [
    {
      "key": "x-python-handler",
      "value": "stream.StreamAPI"
    },
    {
      "key": "x-python-route-line",
      "value": 637
    },
    {
      "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/streams",
  "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": {
    "user_package": 8,
    "listen": [
      {
        "port": 443,
        "protocol": "tcp"
      }
    ],
    "backend_port": 443,
    "backend": [
      {
        "addr": "198.51.100.10",
        "weight": 1,
        "state": "up"
      }
    ]
  },
  "info": {
    "title": "itecdn v5 用户 API",
    "version": "5.x",
    "description": "itecdn v5.x Python 主控用户 API。本文档不适用于 v6 或其它实现。"
  },
  "postman": {
    "name": "创建四层转发",
    "description": {
      "content": "创建一个或多个四层转发。请求体可以是单个对象或对象数组；每项均必须指定用户套餐、监听配置、回源端口和源站列表。未指定的协议、负载方式和 PROXY protocol 使用当前区域及用户默认配置。管理员可额外指定用户、区域、线路和 CNAME 资源。",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "v1",
        "streams"
      ],
      "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"
        }
      ]
    }
  }
}