Assign Users to Workspaces (and Groups)
12 min
API Endpoint Documentation: /api/users/workspace-assign
Description:
This endpoint allows you to assign multiple users to one or more workspaces and groups by sending a POST request. The request body contains user IDs, workspace IDs, and group IDs to establish these assignments.
Endpoint:
POST https://admin.<your-site>.com/api/users/workspace-assign
Headers:
- accept: application/json Specifies that the request expects a JSON response.
- authorization: Bearer <JWT Token> A JSON Web Token (JWT) that authenticates the request. Replace <JWT Token> with a valid token.
- content-type: application/json Specifies that the request body is in JSON format.
Request Body:
The request body should be in JSON format, containing the following fields:
- workspaces: array An array of workspace IDs to which the users will be assigned.
- userIds: array An array of user IDs to be assigned to the workspaces.
- groups: array (Optional) An array of group IDs to which the users will be assigned within the workspaces.
Example Request Body:
{
"workspaces": ["67fc8f559c24f8e146543697"],
"userIds": [
"6762c9a8dea46c90b1d924ec",
"67a350d93e2da4d0491687f0",
"6633bd2b946db532e13a7286"
],
"groups": [
"6804317449913c261b1b3c6f",
"6806af86ee8f019a1266b9ed"
]
}
Method:
- POST: Sends a request to assign the specified users to the specified workspaces and groups.
Example Request (Node.js):
const fetch = require('node-fetch');
const url = 'https://admin.<your-site>.com/api/users/workspace-assign';
const options = {
method: 'POST',
headers: {
'accept': 'application/json',
'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
'content-type': 'application/json'
},
body: JSON.stringify({
workspaces: ["67fc8f559c24f8e146543697"],
userIds: [
"6762c9a8dea46c90b1d924ec",
"67a350d93e2da4d0491687f0",
"6633bd2b946db532e13a7286"
],
groups: [
"6804317449913c261b1b3c6f",
"6806af86ee8f019a1266b9ed"
]
})
};
fetch(url, options)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Response:
The API will return a JSON response indicating the success or failure of the operation.
Success Response (200):
{
"status": 200,
"message": "Users successfully assigned to workspaces."
}
Error Response (400):
{
"status": 400,
"message": "Please select at least one user."
}
Or:
{
"status": 400,
"message": "Please select a valid User."
}
Authentication:
This API requires a valid JWT token for authentication and admin privileges. Ensure that the token is included in the authorization header as Bearer <JWT Token>.
Usage Notes:
- This endpoint requires admin privileges to use.
- You can assign multiple users to multiple workspaces in a single request.
- The system will automatically update the user's type based on their permissions.
- If no users are selected, the request will fail with a 400 error.
- If an invalid user ID is provided, the request will fail with a 400 error.