> ## Documentation Index
> Fetch the complete documentation index at: https://docs.limitly.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Users

> Manage user accounts via the REST API

Manage user accounts and track their usage using the Limitly REST API.

## List Users

Get all users for your account:

```bash theme={null}
curl -X GET \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  https://api.limitly.dev/functions/v1/users
```

### Response

```json theme={null}
{
  "data": [
    {
      "user_id": 123,
      "name": "John Doe",
      "email": "john@example.com",
      "is_disabled": false,
      "created_at": "2024-01-01T00:00:00Z",
      "updated_at": "2024-01-01T00:00:00Z"
    }
  ],
  "count": 1
}
```

## Create User

Create a new user account:

```bash theme={null}
curl -X POST \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "john@example.com"
  }' \
  https://api.limitly.dev/functions/v1/users
```

### Request Parameters

<ParamField body="name" type="string" required>
  The name of the user
</ParamField>

<ParamField body="email" type="string">
  The email address of the user
</ParamField>

### Response

```json theme={null}
{
  "data": {
    "user_id": 123,
    "name": "John Doe",
    "email": "john@example.com",
    "is_disabled": false,
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-01T00:00:00Z"
  }
}
```

## Get User

Retrieve a specific user by ID:

```bash theme={null}
curl -X GET \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  https://api.limitly.dev/functions/v1/users/123
```

### Response

```json theme={null}
{
  "data": {
    "user_id": 123,
    "name": "John Doe",
    "email": "john@example.com",
    "is_disabled": false,
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-01T00:00:00Z"
  }
}
```

## Update User

Update an existing user:

```bash theme={null}
curl -X PUT \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Smith",
    "email": "john.smith@example.com"
  }' \
  https://api.limitly.dev/functions/v1/users/123
```

### Request Parameters

<ParamField body="name" type="string">
  New name for the user
</ParamField>

<ParamField body="email" type="string">
  New email address for the user
</ParamField>

<ParamField body="is_disabled" type="boolean">
  Whether the user account is disabled
</ParamField>

## Delete User

Delete a user account:

```bash theme={null}
curl -X DELETE \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  https://api.limitly.dev/functions/v1/users/123
```

### Response

```json theme={null}
{
  "data": {
    "message": "User deleted successfully"
  }
}
```

## Get User Usage

Get usage statistics for a specific user:

```bash theme={null}
curl -X GET \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  https://api.limitly.dev/functions/v1/users/123/usage
```

### Response

```json theme={null}
{
  "data": {
    "type": "user",
    "current_usage": 45,
    "limit": 1000,
    "percentage_used": 4.5,
    "user_name": "John Doe",
    "plan_name": "Basic Plan"
  }
}
```

## Get User API Keys

Get all API keys associated with a user:

```bash theme={null}
curl -X GET \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  https://api.limitly.dev/functions/v1/users/123/keys
```

### Response

```json theme={null}
{
  "data": [
    {
      "id": "key_123",
      "name": "Production API Key",
      "plan_id": "plan_789",
      "status": "active",
      "created_at": "2024-01-01T00:00:00Z"
    }
  ],
  "count": 1
}
```

## Get User Requests

Get detailed request history for a user:

```bash theme={null}
curl -X GET \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  https://api.limitly.dev/functions/v1/users/123/requests
```

### Response

```json theme={null}
{
  "data": {
    "requests": [
      {
        "timestamp": "2024-01-01T12:00:00Z",
        "endpoint": "/api/users",
        "method": "GET",
        "status": "allowed",
        "ip_address": "192.168.1.1"
      }
    ],
    "count": 1
  }
}
```

## User Status Management

Manage user account status:

```bash theme={null}
# Activate a user
curl -X PUT \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "is_disabled": false
  }' \
  https://api.limitly.dev/functions/v1/users/123

# Suspend a user
curl -X PUT \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  -H "Content-Type: application/json" \
  -d '{
    "is_disabled": true
  }' \
  https://api.limitly.dev/functions/v1/users/123
```

## Search Users

Search for users by various criteria:

```bash theme={null}
# Search by email
curl -X GET \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  "https://api.limitly.dev/functions/v1/users?email=john@example.com"
```

## Error Responses

### User Not Found

```json theme={null}
{
  "error": "User not found",
  "code": "USER_NOT_FOUND"
}
```

### Validation Error

```json theme={null}
{
  "error": "Validation failed",
  "code": "VALIDATION_ERROR",
  "details": {
    "field": "email",
    "message": "Invalid email format"
  }
}
```

### Duplicate Email

```json theme={null}
{
  "error": "Email already exists",
  "code": "DUPLICATE_EMAIL"
}
```

## Pagination

List endpoints support pagination with the following query parameters:

<ParamField body="page" type="number">
  Page number (default: 1)
</ParamField>

<ParamField body="limit" type="number">
  Number of items per page (default: 10, max: 100)
</ParamField>

### Example

```bash theme={null}
curl -X GET \
  -H "Authorization: Bearer lk_1234567890abcdef1234567890abcdef" \
  "https://api.limitly.dev/functions/v1/users?page=2&limit=20"
```

## User Properties

The API supports the following user properties:

* **user\_id**: Unique identifier for the user
* **name**: User's display name
* **email**: User's email address (optional)
* **is\_disabled**: Whether the user account is disabled
* **created\_at**: Timestamp when the user was created
* **updated\_at**: Timestamp when the user was last updated

## Next Steps

* [API Key Management](/rest-api/api-keys) - Create API keys for users
* [Plans](/rest-api/plans) - Assign users to plans
* [Request Validation](/rest-api/validation) - Validate requests for users
