创建一个组织
在 MongoDB Cloud 中创建一个组织,并将其与请求的服务账户或 API 密钥所属的组织相关联。要使用此资源,请求的服务账户或 API 密钥必须具有“组织所有者”角色。发出请求的服务账户或 API 密钥所属的组织必须是付费组织。要了解更多信息,请参阅 MongoDB Atlas 文档中的配置付费组织。
查询参数
-
指示应用程序是否将响应包装在
envelope
JSON 对象中的标志。某些 API 客户端无法访问 HTTP 响应标头或状态代码。要修复此问题,请在查询中设置 Envelope=true。返回结果列表的端点将结果对象用作 envelope。应用程序将状态参数添加到响应正文中。默认值为
false
。 -
指示响应正文是否应采用 prettyprint 格式的标记。
默认值为
false
。Prettyprint
body
必需
要创建的组织。
-
Atlas为此组织创建的组织服务帐户。如果省略, Atlas不会为此组织创建组织服务帐户。如果指定,则该对象需要所有正文参数。请注意,不能在同一请求中指定API密钥。
-
唯一的 24 位十六进制数字字符串,用于标识将新创建的组织链接到的联合。如果指定,新组织的建议组织所有者必须在与联合关联的组织中具有组织所有者角色。
格式应符合以下模式:
^([a-f0-9]{24})$
。 -
用于标识组织的人类可读标签。
格式应符合以下模式:
^[\p{L}\p{N}\-_.(),:&@+']{1,64}$
。 -
唯一的 24 位十六进制数字字符串,用于标识要分配“组织所有者”角色的 MongoDB Cloud 用户。该用户必须与调用的 API 密钥属于同一组织。如果提供
federationSettingsId
,则该用户必须在指定联盟的组织中拥有“组织所有者”角色。只有使用程序化 API 密钥进行身份验证时才需要此参数。格式应符合以下模式:
^([a-f0-9]{24})$
。 -
Atlas为此组织创建的组织服务帐户。如果省略, Atlas不会为此组织创建组织服务帐户。如果指定,则该对象需要所有正文参数。请注意,不能在同一请求中指定API密钥。
-
禁用自动创建警报。 设立为 true 时,不会自动创建组织级别的警报。
默认值为
false
。
atlas api organizations createOrg --help
import (
"os"
"context"
"log"
sdk "go.mongodb.org/atlas-sdk/v20250312001/admin"
)
func main() {
ctx := context.Background()
clientID := os.Getenv("MONGODB_ATLAS_CLIENT_ID")
clientSecret := os.Getenv("MONGODB_ATLAS_CLIENT_SECRET")
// See https://dochub.mongodb.org/core/atlas-go-sdk-oauth
client, err := sdk.NewClient(sdk.UseOAuthAuth(clientID, clientSecret))
if err != nil {
log.Fatalf("Error: %v", err)
}
params = &sdk.CreateOrgApiParams{}
sdkResp, httpResp, err := client.OrganizationsApi.
CreateOrgWithParams(ctx, params).
Execute()
}
curl --include --header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header "Accept: application/vnd.atlas.2025-03-12+json" \
--header "Content-Type: application/json" \
-X POST "https://cloud.mongodb.com/api/atlas/v2/orgs" \
-d '{ <Payload> }'
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
--digest --include \
--header "Accept: application/vnd.atlas.2025-03-12+json" \
--header "Content-Type: application/json" \
-X POST "https://cloud.mongodb.com/api/atlas/v2/orgs" \
-d '{ <Payload> }'
{
"apiKey": {
"desc": "string",
"roles": [
"ORG_OWNER"
]
},
"federationSettingsId": "32b6e34b3d91647abb20e7b8",
"name": "string",
"orgOwnerId": "32b6e34b3d91647abb20e7b8",
"serviceAccount": {
"description": "string",
"name": "string",
"roles": [
"ORG_MEMBER"
],
"secretExpiresAfterHours": 8
},
"skipDefaultAlertsSettings": false
}
{
"apiKey": {
"desc": "string",
"id": "32b6e34b3d91647abb20e7b8",
"links": [
{
"href": "https://cloud.mongodb.com/api/atlas",
"rel": "self"
}
],
"privateKey": "55c3bbb6-b4bb-0be1-e66d20841f3e",
"publicKey": "zmmrboas",
"roles": [
{
"groupId": "32b6e34b3d91647abb20e7b8",
"orgId": "32b6e34b3d91647abb20e7b8",
"roleName": "ORG_MEMBER"
}
]
},
"federationSettingsId": "32b6e34b3d91647abb20e7b8",
"orgOwnerId": "32b6e34b3d91647abb20e7b8",
"organization": {
"id": "32b6e34b3d91647abb20e7b8",
"isDeleted": true,
"links": [
{
"href": "https://cloud.mongodb.com/api/atlas",
"rel": "self"
}
],
"name": "string",
"skipDefaultAlertsSettings": false
},
"serviceAccount": {
"clientId": "mdb_sa_id_1234567890abcdef12345678",
"createdAt": "2025-05-04T09:42:00Z",
"description": "string",
"name": "string",
"roles": [
"ORG_MEMBER"
],
"secrets": [
{
"createdAt": "2025-05-04T09:42:00Z",
"expiresAt": "2025-05-04T09:42:00Z",
"id": "32b6e34b3d91647abb20e7b8",
"lastUsedAt": "2025-05-04T09:42:00Z",
"maskedSecretValue": "mdb_sa_sk_...",
"secret": "mdb_sa_sk_..."
}
]
},
"skipDefaultAlertsSettings": false
}
{
"error": 400,
"detail": "(This is just an example, the exception may not be related to this endpoint) No provider AWS exists.",
"reason": "Bad Request",
"errorCode": "VALIDATION_ERROR"
}
{
"error": 401,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Unauthorized",
"errorCode": "NOT_ORG_GROUP_CREATOR"
}
{
"error": 403,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Forbidden",
"errorCode": "CANNOT_CHANGE_GROUP_NAME"
}
{
"error": 404,
"detail": "(This is just an example, the exception may not be related to this endpoint) Cannot find resource AWS",
"reason": "Not Found",
"errorCode": "RESOURCE_NOT_FOUND"
}
{
"error": 409,
"detail": "(This is just an example, the exception may not be related to this endpoint) Cannot delete organization link while there is active migration in following project ids: 60c4fd418ebe251047c50554",
"reason": "Conflict",
"errorCode": "CANNOT_DELETE_ORG_ACTIVE_LIVE_MIGRATION_ATLAS_ORG_LINK"
}
{
"error": 500,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Internal Server Error",
"errorCode": "UNEXPECTED_ERROR"
}