Overview
The Admin API lets a Factory install create organizations from a script instead of the admin panel. Each request creates an organization, its owner, and a service account inside that organization with administrator rights. The response returns that service account’s credentials, which you then use with the CrewAI Platform API (/api/v1) to configure the organization, for example to add its environment variables.
The Admin API is available on Factory installs only. It is served under /admin-api/v1 on your CrewAI Platform host.
Two kinds of credentials are involved, and each works on one API only:
Before you start
- Complete the Post-Installation steps, including Initialize Internal Organization and Grant Admin Panel Access. Admin API credentials are created in the admin panel and belong to the install’s internal organization.
- Decide how organization owners will sign in. If you pass
owner_external_id, it must be the exact subject (sub) your identity provider issues for that user. See Create an organization.
Create an Admin API credential
- Sign in to the admin panel at
https://<your-host>/admin. - Open API Credentials.
- Enter a Name that describes the integration, such as
provisioning-pipeline, and click Create credential. - Copy the Client ID and Client secret. The secret is shown only once.
Get an access token
Exchange the credential for a short-lived access token with the OAuth 2.0 client credentials flow. This is the same token endpoint organizations use, described in Service accounts.Create an organization
The email of the organization’s owner. If a user with this email already exists on the install, that user becomes the owner; when you also pass
owner_external_id, it must belong to that same user.The owner’s subject identifier (
sub) in your identity provider, exactly as the provider issues it. The owner is matched by this value when they sign in.If you leave it out, the owner is created with a temporary identifier, and the first person to sign in with owner_email through your identity provider claims the account. Pass it whenever you know the subject identifier.Your own identifier for the organization, such as a customer or tenant ID. It must be unique on the install, and you can look organizations up by it later.
201 Created:
- the owner as an Owner of the organization, in its Administrators team;
- a service account named
crewai-org-provisionerin the Administrators team, whose credentials are inservice_account.
k8s_namespace is the namespace the organization’s automations deploy to when Multi-Org Namespaces is enabled, and null otherwise. Create that namespace before the organization deploys its first automation.
Configure the new organization
Use the returnedclient_id and client_secret to get a token for the organization, exactly as in Get an access token, then call the CrewAI Platform API. Because the service account is in the Administrators team, it can manage the organization from its first token.
For example, to add an environment variable the organization’s automations can use:
409 Conflict with the existing variable’s ID, so you can update it instead. See the Platform API reference for every field, including references to an external secrets manager.
Find organizations
List the organizations on the install, optionally filtered byname or reference:
page_size, and use the next_page_token from the response’s meta as page_token to get the next page. order_by=name sorts by name.
Rotate an organization’s credentials
client_id and a new client_secret. The previous secret, and every token issued from it, stops working immediately; there is no grace period.
Errors
Errors use the CrewAI API error envelope, with acode and a detail for each error:
The token endpoint (
/oauth/token) returns OAuth 2.0-style errors instead, such as {"error": "invalid_client"}.