User and Organization APIs
The user interface serves both personal data maintenance and administrator account management; the organization interface is used to read organizations, directly maintain membership relationships, and adjust organizational roles. Both sets of interfaces use integer IDs, not UUIDs.
Please read API Conventions and Authentication and Token Refresh before starting. See Authentication and Permissions for the overall relationship between roles, organization scope and resource permissions.
Choose the Integration Route First
Ordinary Integration
After logging in, ordinary users can:
- Read and maintain your own data;
- Change the password using the current password;
- Check out the organizations you have joined;
- View the organization details visible to you;
- View the member list of your organization;
- Actively quit the organization, but the only organization administrator cannot quit directly.
Ordinary users cannot list platform users, create users, deactivate users, reset other people's passwords, create or delete organizations, or directly add or remove members.
Administrator Integration
The permissions of organization administrators only take effect for the specified organization, and only super administrators have platform-wide permissions. Commonly used boundaries are as follows:
| Action | Organization Administrators | Super Administrator |
|---|---|---|
| List users | Returns only active users in the organizations they manage | Return all active users |
| Create user | Ordinary users can be created, but super administrators cannot be created. | Can create ordinary users or super administrators |
| View, update, deactivate users | Only members of the organizations they manage | all users |
| reset password | The current endpoint allows organization administrators to enter, and there are special instructions for the target scope. | all users |
| View security audit | not allowed | allow |
| Create an organization | not allowed | allow |
| Update organization | Only the organization for which it is an administrator | All organizations |
| Delete organization | not allowed | allow |
| Add, modify or remove members | Only the organization for which they are administrators, and restricted by the administrator role | All organizations still cannot modify or remove their memberships |
"Being an administrator in any organization" does not mean "can manage all organizations." Always bring the target organization ID when calling the organization interface, and check the current user's current_user_role in the organization before the client displays the operation.
Resource Identifiers and Public Fields
User, organization, and membership relationships all use integer primary keys:
/api/users/42/
/api/organizations/7/
Member detail paths have a confusing convention:
/api/organizations/<org_id>/members/<user_id>/
The last segment is the user ID, not id in the membership response. Member responses will also include:
id: membership ID;user_id: User ID;organization: Organization ID.
Before filling in a value to the path, confirm the meaning of the field and do not interchange the three integers.
Common Integration: Reading and Maintaining the Current User
Get Current User Information
GET /api/users/me/
The interface requires login and no user ID is required. You can use fields to select the return field, for example:
GET /api/users/me/?fields=id,username,first_name,phone,company_name,organizations
Common return fields are as follows:
| Field | Meaning |
|---|---|
id | User integer ID |
username | Username |
email | Unique email |
phone | Unique mobile phone number, which can be null |
company_name | Unit name |
first_name | name |
user_type | Platform role: user or super_admin |
date_joined | creation time |
info_updated_time | Data update time |
account_expire_time | Account expiration time, can be null |
password_expires_at | Current password expiry time |
description | Remarks, can be null |
is_active | Is the account enabled? |
organizations | id, name and role of the organization to which they belong |
Minimal read-only request:
export NEXUSFLOW_BASE_URL="https://nexusflow.example.com"
export NEXUSFLOW_ACCESS_TOKEN="<由安全方式注入>"
curl --silent --show-error --fail-with-body \
--header "Accept: application/json" \
--header "Authorization: Bearer ${NEXUSFLOW_ACCESS_TOKEN}" \
"${NEXUSFLOW_BASE_URL%/}/api/users/me/?fields=id,username,first_name,organizations"
Response example:
{
"message": "获取当前用户信息成功",
"code": 0,
"data": {
"id": 42,
"username": "example_user",
"first_name": "示例用户",
"organizations": [
{
"id": 7,
"name": "接口联调组织",
"role": "member"
}
]
}
}
Update Current User Profile
PATCH /api/users/me/
Submit only the fields you want to modify. For profile pages, it is recommended to limit the request whitelist to username, email, phone, company_name, first_name and description:
{
"first_name": "示例用户",
"phone": null,
"company_name": "示例单位"
}
The current implementation only explicitly excludes user_type for non-super administrators, and the underlying update serializer also includes fields such as is_active, account_expire_time, and password. Ordinary integration should not expose these fields as personal data edit items; passwords should use a dedicated password change interface, and account status and expiration time should be maintained by authorized administrators.
Username, email address and non-empty mobile phone number are unique. When the mobile phone number submits an empty string, it will be saved as null; when there are duplicate values or the password strength does not meet the requirements, 400 will be returned and a field error will be given in data.errors.
Modify Current User Password
POST /api/users/me/change-password/
Request body:
{
"old_password": "<当前密码>",
"new_password": "<符合平台强度要求的新密码>"
}
The interface checks the current password, the difference between the old and new passwords, and the current password strength policy. The successfully responded data is null. Do not write both passwords to the command line history, logs, or error reports; the actual call should construct the request body from the secure input or key store.
After the password is changed, the client should update the session status according to the authentication process. Do not assume that all tokens currently held will be automatically replaced by this response. See Authentication and Token Refresh for token handling.
View the Organizations the Current User Belongs To
GET /api/users/me/organizations/
data directly returns the organization array without paging. Each item includes the organization ID, name, description, creator, number of members, and the current requesting user's current_user_role in that organization.
This interface only indicates "which organizations the current user has joined", but does not mean that the user can manage these organizations. Only when current_user_role is admin, or the current user is a super administrator, it is possible to perform the corresponding management operation.
Common Integration: View Organizations and Members
List Visible Organizations
GET /api/organizations/
All logged in users can call it, but the return scope is different:
- Ordinary users and organization administrators can only see the organizations they join;
- Super administrators see all organizations.
Supports search fuzzy search in organization name and description, supports page and page_size. The default is 20 items per page. The valid range of page_size is 1 to 100; when the range is exceeded, it returns to 20. This interface does not support the generic ordering parameter.
GET /api/organizations/?search=联调&page=1&page_size=20
Pagination returns data.results and data.pagination. Common fields for organization objects are:
| Field | Meaning |
|---|---|
id | Organization integer ID |
name / description | name and description |
created_at / updated_at | Creation and update time |
created_by | Creator user ID, which can be null |
created_by_username | Creator username, can be null |
member_count | Current number of members |
current_user_role | The current user is in the organization's admin, member or null |
Get Organization Details
GET /api/organizations/<org_id>/
Ordinary users can only read the organizations they have joined; super administrators can read any organization. Organizations that do not have permission to see are treated as invisible resources and their details should not be inferred from other interface responses.
Get Organization Members
GET /api/organizations/<org_id>/members/
Ordinary members, organization administrators, and super administrators in the organization can read it. Supports search fuzzy search by member user name or email, but the current interface does not paginate, data directly returns the complete member array.
Member items include id, user_id, username, email, company_name, organization, role and joined_at. The member list contains personal information and should not be cached in an unauthorized location or used as a public address book.
Voluntarily Withdraw from the Organization
POST /api/organizations/<org_id>/leave/
The request body can be empty. The current user must already be in the organization:
- Ordinary members can withdraw directly;
- When there are other administrators in the organization, the current administrator can exit;
- When the current user is the only administrator, 400 is returned. Other administrators must be designated by the super administrator, or the role adjustment must be completed through a process with existing permissions.
Signing out removes the current user's membership in the organization. It does not delete user accounts, nor does it delete organizations.
Admin Integration: Manage Users
List Users
GET /api/users/
Can only be called by super administrators or organization administrators of at least one organization. The list only contains users of is_active=true:
- Super administrator can see all active users;
- Organization administrators only see active members of the organizations they manage; users who belong to multiple organizations are returned only once.
Supported query parameters:
| Parameters | Actual Behavior |
|---|---|
page / page_size | Default 1 / 20; page_size valid range is 1 to 100 |
search | Fuzzy search among username, email, organization name, mobile phone number |
search_username、search_email、search_company_name、search_phone | Fuzzy search for each field; press "Any field hit" combination when both are provided |
user_type | Only user or super_admin accepted |
ordering | Sorting can be done by scalar fields, the prefix - indicates descending order, multiple fields are separated by commas; invalid fields are ignored |
fields | Comma separated, only return specified detail fields |
count_only=true | Only return data.count within the current permissions and filtering range |
Regular organization admins cannot expand to other organizations via query parameters. Deactivated users are not in the list; reactivation must be done by already knowing the user ID and using the permissioned details update interface.
Create User
POST /api/users/
Minimum requests require username , email and password :
{
"username": "integration_user",
"email": "integration_user@example.invalid",
"password": "<符合平台强度要求的初始密码>",
"user_type": "user",
"organization_id": 7
}
Optional data fields include phone, company_name, first_name, description, account_expire_time and is_active. Successfully returns HTTP 201 with full user details.
Permissions and organization joining semantics need to be handled separately:
- Organization administrator cannot create
user_type=super_admin; - Super administrators can create ordinary users or super administrators;
- When
organization_idis provided and the caller is an administrator or super administrator of the organization, the new user will join the organization with the rolemember; - The current implementation does not return member joining errors for
organization_idthat is invalid, does not exist, or is beyond the caller's management scope. The user may still be created successfully but not join the organization.
Therefore, you should check the response for organizations after creation, or requery the target organization members. When you need to reliably add existing users to the organization, give priority to using the member addition interface and handle its errors separately.
Get and Update Specified Users
GET /api/users/<user_id>/
PATCH /api/users/<user_id>/
Ordinary users can only access themselves; organization administrators can only access members of the organizations they manage; super administrators can access all users. GET supports fields.
PATCH is a partial update. Current permission restrictions are:
- Only super administrators can modify
user_type; - Super administrators and organization administrators can modify
is_activeandaccount_expire_timewho have the authority to manage target users; - Other data fields are verified by the user update serializer.
Although the underlying general update field contains password, administrator integration should still use the dedicated reset password interface, and ordinary users should use the modify current password interface. In this way, user self-service modifications and administrator resets can be clearly distinguished, and general data updates can be avoided from accidentally carrying passwords.
Deactivate User
DELETE /api/users/<user_id>/
This operation does not physically delete the user record, but sets is_active to false:
- Super administrators can deactivate any user;
- Organization administrators can only deactivate members of the organizations they manage;
- Ordinary users cannot deactivate themselves through this interface.
Successfully returns HTTP 204 with no response body. The client must not continue parsing JSON. Deactivating does not remove organization membership; re-enabling requires a privileged administrator to perform PATCH and set is_active: true on a known user ID.
Administrator Reset Password
POST /api/users/<user_id>/reset-password/
The request body only contains:
{
"new_password": "<符合平台强度要求的新密码>"
}
A successful response will not return the password, only user_id and username of the target user.
The current endpoint only checks at the entrance whether the caller is a super administrator or an administrator of any organization. It does not check again whether the target user belongs to the organization managed by the caller like the user details, update and deactivation interfaces. Organization administrator integration must check the target membership by itself before calling, and this entry permission cannot be understood as full platform user management authorization. Client-side validation is not a substitute for server-side authorization; deployers should factor this difference into security reviews.
Query Security Audit Records
GET /api/users/security-audit/
Only super administrators have access, not organization administrators. This interface reads local security audit records such as logins, token refreshes, and API accesses.
Supported filter parameters:
| Parameters | Description |
|---|---|
event_type | Precise filtering by event type, such as login, token_refresh, api_access |
username | Username fuzzy search |
success | Only valid for true or false |
start_time / end_time | Parsable datetime boundaries; unparsable values are ignored |
page / page_size | Default 1 / 20, page_size limited to 1 to 100 |
The returned fields include id, username, event_type, method, path, success, status_code, source_ip, user_agent, details and created_at. The paging object currently contains page numbers, items per page, total pages, and total quantity, and is not guaranteed to have has_next or has_previous in other lists.
Audit records may contain IP, client information, and access paths and can only be shown to those with real troubleshooting responsibilities. The interface will not return the request body, token or password, and the caller should not record these sensitive contents in the secondary log.
Admin Integration: Manage Organizations
Create an Organization
POST /api/organizations/
Only super administrators can call this. The request fields are only name and optional description:
{
"name": "接口联调组织",
"description": "用于验证组织与成员接口"
}
The organization name will have leading and trailing spaces removed, cannot be empty, and must be unique. Success currently returns HTTP 200 instead of the uniform 201. The creator is recorded as the current super administrator, but the creation of the organization itself will not automatically add a new membership relationship.
Update Organization
PATCH /api/organizations/<org_id>/
Can be called by a super administrator or an organization administrator for this organization. Only name and description are accepted, with partial updates; the name still needs to be unique.
Delete Organization
DELETE /api/organizations/<org_id>/
Only super administrators can call this. It will directly delete the organization record and cascade the organization's membership, not a tombstone like user deactivation. Membership, workspace entitlements, and other external configuration saved by the organization ID should be checked before execution; database cascading cannot automatically prove that all external references have been handled.
Success returns HTTP 200 and a generic response, not 204.
Admin Integration: Manage Members
The current public interface directly maintains the membership relationship between existing active users and organizations. There is no self-service joining, waiting for invitations, or batch import endpoints.
Add Existing User
POST /api/organizations/<org_id>/members/
Can be called by a super administrator or an organization administrator of the target organization. Minimum request:
export NEXUSFLOW_ORG_ID="7"
export NEXUSFLOW_USER_ID="42"
curl --silent --show-error --fail-with-body \
--request POST \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${NEXUSFLOW_ACCESS_TOKEN}" \
--data "{\"user_id\":${NEXUSFLOW_USER_ID},\"role\":\"member\"}" \
"${NEXUSFLOW_BASE_URL%/}/api/organizations/${NEXUSFLOW_ORG_ID}/members/"
Example of successful response:
{
"message": "添加成员成功",
"code": 0,
"data": {
"id": 105,
"user_id": 42,
"username": "example_user",
"email": "example_user@example.invalid",
"company_name": "示例单位",
"organization": 7,
"role": "member",
"joined_at": "2026-08-29 10:30:00"
}
}
The target user must exist and be enabled, and the same user cannot join the same organization repeatedly. role defaults to member when omitted. Only super administrators can directly specify role: "admin" when adding; organization administrators can only add ordinary members.
Modify Member Role
PATCH /api/organizations/<org_id>/members/<user_id>/
Request body:
{
"role": "admin"
}
role can only be admin or member. The restrictions are as follows:
- No caller can modify his or her role in the target organization through this interface;
- Only super administrators can promote ordinary members to administrators;
- Non-super administrators cannot modify the roles of existing administrators;
- Super administrators can adjust the roles of other members.
Therefore, organization administrators cannot expand the number of administrators by themselves through this interface. When the only administrator plans to exit, the super administrator needs to set another member as an administrator first.
Remove Member
DELETE /api/organizations/<org_id>/members/<user_id>/
A super administrator or an organization administrator of the target organization can call, but:
- You cannot remove yourself, you should use the active exit interface;
- Organization administrators cannot remove other administrators;
- Super administrators can remove other administrators or ordinary members.
Returns HTTP 200 and generic response on success. Removing a member only deletes the membership relationship and does not deactivate the user account.
Conflict and Error Handling
| Scene | Common Results | Caller Handling |
|---|---|---|
| Duplicate username, email address or non-empty mobile phone number | 400 , field error is located at data.errors | Prompt to replace the unique value and do not automatically retry |
| The password does not comply with the policy and the old password is wrong | 400, field or non-field error | Do not record the password, press the error field prompt |
| Organization name is duplicate or empty | 400,data.errors.name | Correct the name and resubmit |
| Add non-existent or deactivated user | 400 | Recheck user ID and enabled status |
| Add members repeatedly | 400 | Query the member list to avoid repeated submissions |
| Modify your organizational role and exit as the only administrator | 400 | Arrange other administrators first, and then exit |
| Not logged in or token invalid | 401 | Refresh or log in again according to the authentication process |
| The role is correct but the target is outside the scope of management | 403 | Check the target organization and member relationships, and bypass it by not replacing it with a wide-privilege account. |
| User, organization or membership relationship does not exist | 404 | Reread the list; don't guess the new integer ID |
| Deactivated user successfully | 204, no response body | Treat as successful, do not parse JSON |
An exception is organization_id when creating a user: failure to join the organization may not fail the user creation request. For businesses that require atomic "create and join", the current public interface does not have transactional batch operations; the caller should regard creating a user and verifying membership as two steps, and prepare a clear manual processing or compensation process for the failure of the second step.
Checks Before Integration Is Complete
- Use integer user ID, organization ID and membership ID, and confirm that the member path passes the user ID;
- Ordinary users only call self-service and visible organization interfaces;
- Every write operation by an organization administrator checks the target organization instead of just checking "has an administrator role";
- Organization creation, organization deletion and security auditing exclusive to super administrators are not exposed to organization administrators;
- Passwords are only handled through a dedicated interface and secure input;
- 204 responses after user deactivation do not trigger JSON parsing;
- After adding members, re-read the member list and confirm the organization, user and role;
- Process 400, 401, 403, 404 and 204 without text separately, not just read
message.