创建邀请
创建邀请。key 持有者必须是组织管理员;邀请人记录为 key 持有者。响应中的被邀请人联系方式已脱敏,与列表端点口径一致。
POST
/
v1
/
admin
/
organizations
/
invites
创建邀请
curl --request POST \
--url https://api.moonshot.cn/v1/admin/organizations/invites \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"invitee": "ops@example.com",
"invitee_type": "email",
"role": "member"
}
'import requests
url = "https://api.moonshot.cn/v1/admin/organizations/invites"
payload = {
"invitee": "ops@example.com",
"invitee_type": "email",
"role": "member"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({invitee: 'ops@example.com', invitee_type: 'email', role: 'member'})
};
fetch('https://api.moonshot.cn/v1/admin/organizations/invites', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/admin/organizations/invites",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'invitee' => 'ops@example.com',
'invitee_type' => 'email',
'role' => 'member'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/admin/organizations/invites"
payload := strings.NewReader("{\n \"invitee\": \"ops@example.com\",\n \"invitee_type\": \"email\",\n \"role\": \"member\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/admin/organizations/invites")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"invitee\": \"ops@example.com\",\n \"invitee_type\": \"email\",\n \"role\": \"member\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/admin/organizations/invites")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"invitee\": \"ops@example.com\",\n \"invitee_type\": \"email\",\n \"role\": \"member\"\n}"
response = http.request(request)
puts response.read_body{
"code": "<string>",
"role": "admin",
"status": "pending",
"invitee": "<string>",
"nick_name": "<string>"
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}本接口要求 Admin Key 具备
org:write 作用域,且调用时 key 持有者仍是组织管理员(否则返回 403 owner_not_admin)。昵称仅支持中文、字母与数字(1-32 字符)。未填昵称时系统自动生成:邮箱邀请取邮箱地址中 @ 前的部分并去除不支持的字符;手机号邀请统一使用默认昵称 user,不会使用手机号生成。授权
Authorization 请求头携带 Admin API secret 作为 Bearer 令牌,格式为 Bearer sk-admin-***。Admin Key 可在「控制台 → 组织管理 → Admin API Keys」创建。
请求体
application/json
手机号或邮箱地址,取决于 invitee_type。
示例:
"ops@example.com"
联系方式类型:phone 手机号、email 邮箱。
可用选项:
phone, email 示例:
"email"
被邀请人加入后的组织角色:admin 或 member。
可用选项:
admin, member 示例:
"member"
被邀请人展示昵称(1-32 个字符,仅支持中文、字母与数字)。缺省时自动生成:邮箱邀请取邮箱地址中 @ 前的部分并去除不支持的字符;手机号邀请统一使用默认昵称,不基于手机号生成。
响应
已创建的邀请(被邀请人已脱敏)。
邀请码。明文返回,可用于精确查询同一邀请。
被邀请人加入后的组织角色:admin 或 member。
可用选项:
admin, member 邀请状态:pending 待接受、accepted 已接受。
可用选项:
pending, accepted 脱敏后的被邀请人联系方式:邮箱保留 local part 首字母(如 a***@x.com),手机号保留前 3 位与后 4 位、中段打码(如 138****1234)。列表、详情与创建接口三处均按此脱敏。
被邀请人展示昵称。
此页面对您有帮助吗?
⌘I
创建邀请
curl --request POST \
--url https://api.moonshot.cn/v1/admin/organizations/invites \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"invitee": "ops@example.com",
"invitee_type": "email",
"role": "member"
}
'import requests
url = "https://api.moonshot.cn/v1/admin/organizations/invites"
payload = {
"invitee": "ops@example.com",
"invitee_type": "email",
"role": "member"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({invitee: 'ops@example.com', invitee_type: 'email', role: 'member'})
};
fetch('https://api.moonshot.cn/v1/admin/organizations/invites', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/admin/organizations/invites",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'invitee' => 'ops@example.com',
'invitee_type' => 'email',
'role' => 'member'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/admin/organizations/invites"
payload := strings.NewReader("{\n \"invitee\": \"ops@example.com\",\n \"invitee_type\": \"email\",\n \"role\": \"member\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/admin/organizations/invites")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"invitee\": \"ops@example.com\",\n \"invitee_type\": \"email\",\n \"role\": \"member\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/admin/organizations/invites")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"invitee\": \"ops@example.com\",\n \"invitee_type\": \"email\",\n \"role\": \"member\"\n}"
response = http.request(request)
puts response.read_body{
"code": "<string>",
"role": "admin",
"status": "pending",
"invitee": "<string>",
"nick_name": "<string>"
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}