List all Users
10 min
API Endpoint Documentation: /api/users
Description:
This endpoint allows you to fetch a list of users. You can optionally filter the users based on their type and search by keyword.
Endpoint:
GET https://<your-site>/api/users?type=user,editor&keyword=johnQuery Parameters:
- type: string Comma-separated list of user types to filter by (e.g., user, editor, admin). (Example shown above is for all basic users and editors)
- keyword: string A keyword to search for users. Leave empty to return all users matching the specified types. (Example shown above is for case-insensitive "john")
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.
Method:
- GET: Sends a request to retrieve a list of users based on the specified filters and optional keyword search.
Example Request (Node.js):
const fetch = require('node-fetch');
const url = 'https://<your-site>/api/users?type=user,editor&keyword=';
const options = {
method: 'GET',
headers: {
'accept': 'application/json',
'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
}
};
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 containing user data matching the request filters.
Success Response (200):
{
"data": [
{
"id": "630f68e2c059e9775a633c7f",
"name": "User1",
"email": "[email protected]",
"type": "user",
},
{
"id": "640f68e2c059e9775a633c80",
"name": "Editor1",
"email": "[email protected]",
"type": "editor",
}
],
"status": "success"
}Error Response (400/401):
{
"message": "Invalid token or request",
"status": "error"
}Authentication:
This API requires a valid JWT token for authentication. Ensure that the token is included in the authorization header as Bearer <JWT Token>.
Usage Notes:
- Ensure that the type parameter correctly filters users (e.g., user, editor, admin).
- You can pass an empty keyword parameter to return all users of the specified type.
- The request will return an error if the authorization token is invalid or missing.