跳转至

创建组织

POST /api/v5/orgs

该接口用于创建组织,提交组织路径、名称、可见性及描述等信息后,在平台中新建一个组织,并返回所创建组织的 ID、网页地址、完整名称与完整路径等信息。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
access_token query string 是 用户授权码

Request Body:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "description": "组织名称,默认等于 path",
      "type": "string"
    },
    "path": {
      "description": "组织路径",
      "type": "string"
    },
    "visibility": {
      "description": "可见性:`public` 为公开,`private` 为私有;默认 `public`",
      "type": "string",
      "enum": ["public", "private"],
      "default": "public"
    },
    "description": {
      "description": "组织描述",
      "type": "string"
    }
  },
  "required": ["path"]
}

响应参数

字段 类型 必返 可为空 说明
id integer 是 否 组织 ID
web_url string 是 否 组织网页地址
name string 是 否 组织名称
path string 是 否 组织路径
description string 是 否 组织描述
visibility string 是 否 可见性
full_name string 是 否 组织完整名称
full_path string 是 否 组织完整路径

失败响应

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

400 参数错误

{
  "error": "invalid_request",
  "message": "参数 path 不能为空",
  "field": "path"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)

请求示例

参数说明

<token> 替换为你的 AtomGit 用户访问令牌。

cURL

curl -X POST 'https://api.atomgit.com/api/v5/orgs?access_token=<token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "example-org",
    "path": "example-org",
    "visibility": "public",
    "description": "This is an example organization"
  }'

JavaScript

const response = await fetch("https://api.atomgit.com/api/v5/orgs?access_token=<YOUR-TOKEN>", {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "example-org",
    path: "example-org",
    visibility: "public",
    description: "This is an example organization",
  }),
});

if (!response.ok) {
  throw new Error(`请求失败: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.post(
    "https://api.atomgit.com/api/v5/orgs",
    params={"access_token": "<YOUR-TOKEN>"},
    json={
        "name": "example-org",
        "path": "example-org",
        "visibility": "public",
        "description": "This is an example organization",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "id": 123,
  "web_url": "https://api.atomgit.com/example-org",
  "name": "example-org",
  "path": "example-org",
  "description": "This is an example organization",
  "visibility": "public",
  "full_name": "example-org",
  "full_path": "example-org"
}

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
400 参数错误或请求无法解析
404 请求路径不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc