User Management API 
The User Management API allows you to create and manage user sessions for the embedded domain interface.
Create User Session 
Creates a new user session and returns a login URL for the embedded interface.
Endpoint: POST /api/v1/users
Request 
http
POST /api/v1/users
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
{
  "user_identifier": "string",
  "email": "string" // optional
}Parameters 
| Parameter | Type | Required | Description | 
|---|---|---|---|
| user_identifier | string | Yes | Your unique internal user ID (max 255 chars) | 
| email | string | No | User's email address for better UX | 
Constraints 
- user_identifiermust be unique per API key
- user_identifiercan contain letters, numbers, underscores, and hyphens only
- emailmust be a valid email address format if provided
Response 
json
{
  "user_identifier": "user_123",
  "login_url": "https://embed.pocketdns.com/session/abc123def456",
  "expires_at": "2025-01-07T12:00:00Z"
}Response Fields 
| Field | Type | Description | 
|---|---|---|
| user_identifier | string | The user identifier that was provided | 
| login_url | string | URL to embed in iframe (valid for 24 hours) | 
| expires_at | string | ISO 8601 timestamp when the session expires | 
Examples 
Basic User Session 
javascript
const response = await fetch('https://api.pocketdns.com/api/v1/users', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_live_...',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    user_identifier: 'user_123'
  })
});
const { login_url } = await response.json();User Session with Email 
javascript
const response = await fetch('https://api.pocketdns.com/api/v1/users', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_live_...',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    user_identifier: 'user_123',
    email: '[email protected]'
  })
});
const session = await response.json();Error Responses 
400 Bad Request 
json
{
  "error": "validation_error",
  "message": "user_identifier is required",
  "details": {
    "field": "user_identifier",
    "code": "missing_required_field"
  }
}401 Unauthorized 
json
{
  "error": "unauthorized",
  "message": "Invalid API key"
}422 Unprocessable Entity 
json
{
  "error": "validation_error",
  "message": "Invalid email format",
  "details": {
    "field": "email",
    "code": "invalid_format"
  }
}Get User Details 
Retrieves information about a specific user.
Endpoint: GET /api/v1/users/{user_identifier}
Request 
http
GET /api/v1/users/user_123
Authorization: Bearer YOUR_API_KEYResponse 
json
{
  "user_identifier": "user_123",
  "email": "[email protected]",
  "created_at": "2025-01-01T00:00:00Z",
  "last_login": "2025-01-06T12:00:00Z",
  "domain_count": 5,
  "total_spent": "125.50"
}Examples 
javascript
const response = await fetch('https://api.pocketdns.com/api/v1/users/user_123', {
  headers: {
    'Authorization': 'Bearer sk_live_...'
  }
});
const user = await response.json();
console.log(`User has ${user.domain_count} domains`);List Users 
Retrieves a paginated list of users.
Endpoint: GET /api/v1/users
Request 
http
GET /api/v1/users?limit=50&offset=0&sort=created_at
Authorization: Bearer YOUR_API_KEYQuery Parameters 
| Parameter | Type | Default | Description | 
|---|---|---|---|
| limit | integer | 50 | Number of users to return (max 100) | 
| offset | integer | 0 | Number of users to skip | 
| sort | string | created_at | Sort field ( created_at,last_login,domain_count) | 
| order | string | desc | Sort order ( ascordesc) | 
Response 
json
{
  "users": [
    {
      "user_identifier": "user_123",
      "email": "[email protected]",
      "created_at": "2025-01-01T00:00:00Z",
      "last_login": "2025-01-06T12:00:00Z",
      "domain_count": 5
    }
  ],
  "total": 1247,
  "limit": 50,
  "offset": 0
}Examples 
javascript
// Get first 25 users
const response = await fetch('https://api.pocketdns.com/api/v1/users?limit=25', {
  headers: {
    'Authorization': 'Bearer sk_live_...'
  }
});
const { users, total } = await response.json();
console.log(`Showing ${users.length} of ${total} users`);Update User 
Updates user information.
Endpoint: PUT /api/v1/users/{user_identifier}
Request 
http
PUT /api/v1/users/user_123
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
{
  "email": "[email protected]"
}Parameters 
| Parameter | Type | Required | Description | 
|---|---|---|---|
| email | string | No | New email address | 
Response 
json
{
  "user_identifier": "user_123",
  "email": "[email protected]",
  "updated_at": "2025-01-06T12:30:00Z"
}Examples 
javascript
const response = await fetch('https://api.pocketdns.com/api/v1/users/user_123', {
  method: 'PUT',
  headers: {
    'Authorization': 'Bearer sk_live_...',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    email: '[email protected]'
  })
});
const updatedUser = await response.json();Delete User 
Deletes a user and all associated data.
Endpoint: DELETE /api/v1/users/{user_identifier}
Request 
http
DELETE /api/v1/users/user_123
Authorization: Bearer YOUR_API_KEYResponse 
http
204 No ContentExamples 
javascript
const response = await fetch('https://api.pocketdns.com/api/v1/users/user_123', {
  method: 'DELETE',
  headers: {
    'Authorization': 'Bearer sk_live_...'
  }
});
if (response.status === 204) {
  console.log('User deleted successfully');
}Common Error Codes 
| Status Code | Error Code | Description | 
|---|---|---|
| 400 | validation_error | Request data is invalid | 
| 401 | unauthorized | Invalid or missing API key | 
| 404 | not_found | User not found | 
| 409 | conflict | User identifier already exists | 
| 422 | unprocessable_entity | Data format is correct but values are invalid | 
| 429 | rate_limit_exceeded | Too many requests | 
| 500 | internal_error | Server error | 
Rate Limits 
- User creation: 100 requests per minute
- User retrieval: 1000 requests per minute
- User updates: 60 requests per minute
- User deletion: 30 requests per minute
Rate limit headers are included in all responses:
http
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1641472800Best Practices 
- Cache user sessions to avoid unnecessary API calls
- Handle rate limits gracefully with exponential backoff
- Validate user identifiers before sending to API
- Use meaningful user identifiers for easier debugging
- Include email when available for better user experience
- Check session expiration before using login URLs
