邀请企业成员¶
POST /api/v8/enterprises/{enterprise}/memberships/{username}
用户调用此接口,进行邀请企业成员操作。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
enterprise |
path | integer | 是 | 企业 id |
username |
path | string | 是 | 用户名(username/login) |
access_token |
query | string | 是 | 用户授权码 |
Request Body:
请求体用于指定被邀请成员的权限与角色,以 application/json 格式提交。请求体可省略,省略时新成员默认获得 push 权限。
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"permission": {
"description": "成员权限:参与者(pull)、开发者(push)、维护者(admin)、customized(自定义角色);默认 `push`",
"type": "string",
"enum": ["pull", "push", "admin", "customized"],
"default": "push"
},
"role_id": {
"description": "角色 ID,如果 `permission` 传入了 `customized`,则需要传入角色 ID",
"type": "string"
}
}
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
followers_url |
string | 是 | 否 | 关注者列表地址 |
html_url |
string | 是 | 否 | 主页地址 |
id |
string | 是 | 否 | 成员 ID |
login |
string | 是 | 否 | 用户名(username/login) |
name |
string | 是 | 否 | 姓名 |
type |
string | 是 | 否 | 用户类型 |
url |
string | 是 | 否 | 用户主页地址 |
permissions |
object | 是 | 否 | 成员权限信息 |
permissions 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
permissions.admin |
boolean | 是 | 否 | 是否拥有管理员权限 |
permissions.customized |
boolean | 是 | 否 | 是否拥有自定义角色权限 |
permissions.push |
boolean | 是 | 否 | 是否拥有推送(push)权限 |
permissions.pull |
boolean | 是 | 否 | 是否拥有拉取(pull)权限 |
失败响应¶
接口在参数校验失败、未认证或资源不存在时返回以下错误结构(错误字段名以后端实际返回为准)。
400 参数错误
401 未认证
404 资源不存在
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(Bad Request) |
401 |
需要认证(Requires authentication) |
404 |
资源不存在(Not Found) |
请求示例¶
参数说明¶
<enterprise>替换为企业 id(整数);<username>替换为被邀请成员的用户名(username/login);<token>替换为你的 AtomGit 用户访问令牌。
cURL¶
curl -X POST 'https://api.atomgit.com/api/v8/enterprises/<enterprise>/memberships/<username>?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"permission": "push"}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v8/enterprises/<enterprise>/memberships/<username>?access_token=<token>",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({ permission: "push" }),
}
);
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/v8/enterprises/<enterprise>/memberships/<username>",
params={"access_token": "<token>"},
headers={
"Content-Type": "application/json",
"Accept": "application/json",
},
json={"permission": "push"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"followers_url": "https://api.atomgit.com/api/v5/users/xiaogang2/followers",
"html_url": "https://api.atomgit.com/xiaogang2",
"id": "65ffca965079ba0d1c00f6f2",
"login": "xiaogang2",
"name": "肖刚2",
"type": "User",
"url": "https://api.atomgit.com/api/v5/xiaogang2",
"permissions": {
"admin": false,
"customized": true,
"push": true,
"pull": true
}
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
404 |
请求路径不存在或资源不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc