Skip to content

User Management

Manage users through the API.

The User Object

json
{
  "id": "usr_123",
  "name": "John Doe",
  "email": "john@example.com",
  "role": "admin",
  "status": "active",
  "avatar": "https://example.com/avatars/usr_123.jpg",
  "created_at": "2025-01-01T00:00:00Z",
  "updated_at": "2025-01-15T10:30:00Z"
}

Attributes

AttributeTypeDescription
idstringUnique identifier for the user
namestringUser's full name
emailstringUser's email address
rolestringUser role: admin, user, viewer
statusstringAccount status: active, inactive, suspended
avatarstringURL to user's avatar image
created_atstringISO 8601 timestamp of creation
updated_atstringISO 8601 timestamp of last update

List All Users

Retrieve a paginated list of users.

http
GET /v1/users

Query Parameters

ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger20Items per page (max: 100)
rolestring-Filter by role
statusstring-Filter by status
searchstring-Search by name or email

Example Request

bash
curl -X GET "https://api.example.com/v1/users?page=1&limit=20&role=admin" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

json
{
  "success": true,
  "data": [
    {
      "id": "usr_123",
      "name": "John Doe",
      "email": "john@example.com",
      "role": "admin",
      "status": "active",
      "avatar": "https://example.com/avatars/usr_123.jpg",
      "created_at": "2025-01-01T00:00:00Z",
      "updated_at": "2025-01-15T10:30:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 1,
    "pages": 1
  }
}

Get a User

Retrieve details of a specific user.

http
GET /v1/users/{user_id}

Example Request

bash
curl -X GET https://api.example.com/v1/users/usr_123 \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

json
{
  "success": true,
  "data": {
    "id": "usr_123",
    "name": "John Doe",
    "email": "john@example.com",
    "role": "admin",
    "status": "active",
    "avatar": "https://example.com/avatars/usr_123.jpg",
    "created_at": "2025-01-01T00:00:00Z",
    "updated_at": "2025-01-15T10:30:00Z"
  }
}

Create a User

Create a new user.

http
POST /v1/users

Request Body

json
{
  "name": "Jane Smith",
  "email": "jane@example.com",
  "role": "user",
  "password": "secure_password_123"
}

Example Request

bash
curl -X POST https://api.example.com/v1/users \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Jane Smith",
    "email": "jane@example.com",
    "role": "user",
    "password": "secure_password_123"
  }'

Example Response

json
{
  "success": true,
  "data": {
    "id": "usr_456",
    "name": "Jane Smith",
    "email": "jane@example.com",
    "role": "user",
    "status": "active",
    "created_at": "2025-01-20T15:00:00Z",
    "updated_at": "2025-01-20T15:00:00Z"
  },
  "message": "User created successfully"
}

Update a User

Update an existing user's information.

http
PATCH /v1/users/{user_id}

Request Body

json
{
  "name": "John Smith",
  "role": "admin"
}

Example Request

bash
curl -X PATCH https://api.example.com/v1/users/usr_123 \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Smith",
    "role": "admin"
  }'

Example Response

json
{
  "success": true,
  "data": {
    "id": "usr_123",
    "name": "John Smith",
    "email": "john@example.com",
    "role": "admin",
    "status": "active",
    "updated_at": "2025-01-20T16:00:00Z"
  },
  "message": "User updated successfully"
}

Delete a User

Delete a user permanently.

http
DELETE /v1/users/{user_id}

Example Request

bash
curl -X DELETE https://api.example.com/v1/users/usr_123 \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

json
{
  "success": true,
  "message": "User deleted successfully"
}

Error Responses

400 Bad Request

json
{
  "success": false,
  "error": {
    "code": "invalid_request",
    "message": "Invalid email format",
    "field": "email"
  }
}

404 Not Found

json
{
  "success": false,
  "error": {
    "code": "not_found",
    "message": "User not found"
  }
}

409 Conflict

json
{
  "success": false,
  "error": {
    "code": "duplicate_email",
    "message": "A user with this email already exists"
  }
}

Released under the MIT License.