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

# Users API

> Manage user profiles and settings

# Users API

Endpoints for managing user profiles, settings, and related data.

## Get Current User

Retrieve the authenticated user's profile.

<CodeGroup>
  ```bash Request theme={null}
  curl -X GET "https://api.usmewe.com/v1/users/me" \
    -H "Authorization: Bearer YOUR_TOKEN"
  ```

  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "id": "user_abc123",
      "email": "user@example.com",
      "displayName": "Alice",
      "walletAddress": "0x1234...5678",
      "trustScore": 56,
      "level": "Gold",
      "xp": 2450,
      "createdAt": "2024-01-01T00:00:00Z",
      "settings": {
        "notifications": true,
        "emailAlerts": true,
        "language": "en"
      }
    }
  }
  ```
</CodeGroup>

## Get User by ID

Retrieve a user's public profile.

<CodeGroup>
  ```bash Request theme={null}
  curl -X GET "https://api.usmewe.com/v1/users/{userId}"
  ```

  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "id": "user_abc123",
      "displayName": "Alice",
      "walletAddress": "0x1234...5678",
      "trustScore": 56,
      "level": "Gold",
      "badges": ["early_adopter", "perfect_payer"],
      "createdAt": "2024-01-01T00:00:00Z"
    }
  }
  ```
</CodeGroup>

<Note>
  Private fields like email and settings are only visible to the user themselves.
</Note>

## Update Profile

Update the current user's profile.

<CodeGroup>
  ```bash Request theme={null}
  curl -X PATCH "https://api.usmewe.com/v1/users/me" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "displayName": "Alice Smith",
      "settings": {
        "notifications": true,
        "emailAlerts": false
      }
    }'
  ```

  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "id": "user_abc123",
      "displayName": "Alice Smith",
      "settings": {
        "notifications": true,
        "emailAlerts": false,
        "language": "en"
      },
      "updatedAt": "2024-01-15T12:00:00Z"
    }
  }
  ```
</CodeGroup>

### Updatable Fields

| Field                    | Type    | Description         |
| ------------------------ | ------- | ------------------- |
| `displayName`            | string  | Public display name |
| `settings.notifications` | boolean | Push notifications  |
| `settings.emailAlerts`   | boolean | Email notifications |
| `settings.language`      | string  | Preferred language  |

## Get User XP & Level

Get detailed XP and level information.

<CodeGroup>
  ```bash Request theme={null}
  curl -X GET "https://api.usmewe.com/v1/users/{userId}/xp" \
    -H "Authorization: Bearer YOUR_TOKEN"
  ```

  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "userId": "user_abc123",
      "xp": 2450,
      "level": "Gold",
      "nextLevel": "Platinum",
      "xpToNextLevel": 2550,
      "progressPercent": 49,
      "badges": [
        {
          "id": "early_adopter",
          "name": "Early Adopter",
          "earnedAt": "2024-01-01T00:00:00Z"
        },
        {
          "id": "perfect_payer",
          "name": "Perfect Payer",
          "earnedAt": "2024-01-10T00:00:00Z"
        }
      ]
    }
  }
  ```
</CodeGroup>

## Get User Activity

Get recent activity history.

<CodeGroup>
  ```bash Request theme={null}
  curl -X GET "https://api.usmewe.com/v1/users/me/activity?limit=10" \
    -H "Authorization: Bearer YOUR_TOKEN"
  ```

  ```json Response theme={null}
  {
    "success": true,
    "data": [
      {
        "id": "act_1",
        "type": "loan_repaid",
        "description": "Repaid loan #123",
        "xpEarned": 20,
        "timestamp": "2024-01-15T10:00:00Z"
      },
      {
        "id": "act_2",
        "type": "vault_deposit",
        "description": "Deposited 100 USDC",
        "xpEarned": 25,
        "timestamp": "2024-01-14T15:30:00Z"
      }
    ],
    "pagination": {
      "total": 45,
      "limit": 10,
      "offset": 0,
      "hasMore": true
    }
  }
  ```
</CodeGroup>

### Activity Types

| Type             | Description               |
| ---------------- | ------------------------- |
| `loan_created`   | Created a loan request    |
| `loan_repaid`    | Repaid a loan             |
| `vault_deposit`  | Deposited to Trust Vault  |
| `vault_withdraw` | Withdrew from Trust Vault |
| `guardian_added` | Added a guardian          |
| `level_up`       | Leveled up                |

## Get User Guardians

List the user's guardians.

<CodeGroup>
  ```bash Request theme={null}
  curl -X GET "https://api.usmewe.com/v1/users/me/guardians" \
    -H "Authorization: Bearer YOUR_TOKEN"
  ```

  ```json Response theme={null}
  {
    "success": true,
    "data": [
      {
        "id": "guardian_1",
        "walletAddress": "0xabc...def",
        "displayName": "Bob",
        "status": "active",
        "addedAt": "2024-01-05T00:00:00Z"
      },
      {
        "id": "guardian_2",
        "walletAddress": "0x123...456",
        "displayName": "Carol",
        "status": "pending",
        "addedAt": "2024-01-10T00:00:00Z"
      }
    ]
  }
  ```
</CodeGroup>

## Export User Data

Export all user data (GDPR compliance).

<CodeGroup>
  ```bash Request theme={null}
  curl -X GET "https://api.usmewe.com/v1/users/me/export" \
    -H "Authorization: Bearer YOUR_TOKEN"
  ```

  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "profile": { ... },
      "activity": [ ... ],
      "loans": [ ... ],
      "vaultHistory": [ ... ],
      "guardians": [ ... ],
      "exportedAt": "2024-01-15T12:00:00Z"
    }
  }
  ```
</CodeGroup>

## Delete Account

Request account deletion.

<CodeGroup>
  ```bash Request theme={null}
  curl -X DELETE "https://api.usmewe.com/v1/users/me" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "confirmation": "DELETE_MY_ACCOUNT"
    }'
  ```

  ```json Response theme={null}
  {
    "success": true,
    "message": "Account scheduled for deletion within 30 days",
    "deletionDate": "2024-02-15T00:00:00Z"
  }
  ```
</CodeGroup>

<Warning>
  Account deletion is irreversible. On-chain data cannot be deleted.
</Warning>

## Error Responses

| Code | Error              | Description               |
| ---- | ------------------ | ------------------------- |
| 401  | `UNAUTHORIZED`     | Invalid or missing token  |
| 403  | `FORBIDDEN`        | Access denied to resource |
| 404  | `USER_NOT_FOUND`   | User does not exist       |
| 422  | `VALIDATION_ERROR` | Invalid request data      |
