The Users module allows you to create and manage user accounts, track their usage, and associate them with plans.
List Users
Get all users for your account:
import { Limitly } from '@limitly/limitly-js';
const limitly = new Limitly({
apiKey: 'your_limitly_api_key'
});
// List all users
const users = await limitly.users.list();
console.log('Users:', users.data);
Create User
Create a new user account:
const user = await limitly.users.create({
name: 'John Doe',
email: 'john@example.com',
plan_id: 'plan_123'
});
console.log('Created User:', user.data);
Create User Parameters
The email address of the user
The ID of the plan to associate with this user
Additional metadata for the user
Get User
Retrieve a specific user by ID:
const user = await limitly.users.get('user_123');
console.log('User:', user.data);
Update User
Update an existing user:
const updatedUser = await limitly.users.update('user_123', {
name: 'John Smith',
plan_id: 'plan_456',
metadata: {
company: 'Acme Corp',
role: 'developer'
}
});
console.log('Updated User:', updatedUser.data);
Update User Parameters
Updated plan ID to associate with the user
Updated metadata for the user
Delete User
Delete a user account (soft delete):
const result = await limitly.users.delete('user_123');
console.log('Delete result:', result.data?.message);
Get User Usage
Get usage statistics for a specific user:
const usage = await limitly.users.getUsage('user_123');
console.log('User usage:', usage.data);
User Usage Response
Current usage count for the period
The limit for the current period
Remaining requests for the period
When the usage will reset (ISO 8601 format)
The name of the user’s current plan
Get User API Keys
Get all API keys for a specific user:
const apiKeys = await limitly.users.getApiKeys('user_123');
console.log('User API Keys:', apiKeys.data);
Get User Requests
Get detailed request history for a user:
const requests = await limitly.users.getRequests('user_123');
console.log('User requests:', requests.data);
User Requests Response
When the request was made (ISO 8601 format)
The endpoint that was called
The validation status (allowed/denied)
The ID of the API key used for the request
Complete Example
import { Limitly } from '@limitly/limitly-js';
const limitly = new Limitly({
apiKey: 'your_limitly_api_key'
});
async function manageUsers() {
// Create a new user
const user = await limitly.users.create({
name: 'Jane Doe',
email: 'jane@example.com',
plan_id: 'plan_123',
metadata: {
company: 'Tech Corp',
role: 'developer'
}
});
console.log('Created User:', user.data?.user_id);
// Get user usage
const usage = await limitly.users.getUsage(user.data?.user_id!);
console.log('Current usage:', usage.data?.current_usage);
console.log('Limit:', usage.data?.limit);
console.log('Remaining:', usage.data?.remaining);
// Get user's API keys
const apiKeys = await limitly.users.getApiKeys(user.data?.user_id!);
console.log('User API Keys:', apiKeys.data);
// Get user's request history
const requests = await limitly.users.getRequests(user.data?.user_id!);
console.log('Recent requests:', requests.data?.requests);
// Update the user
await limitly.users.update(user.data?.user_id!, {
name: 'Jane Smith',
plan_id: 'plan_456',
metadata: {
company: 'Tech Corp',
role: 'senior_developer',
department: 'engineering'
}
});
}
User Object
The user object contains the following properties:
Unique identifier for the user
The email address of the user
The ID of the plan associated with this user
When the user was created (ISO 8601 format)
When the user was last updated (ISO 8601 format)
Additional metadata for the user
User Management Best Practices
User Organization
Use metadata to organize users by company, team, or role. This helps with reporting and management.
Plan Assignment
Always assign users to appropriate plans based on their needs and usage patterns.
Usage Monitoring
Regularly monitor user usage to identify patterns and optimize plan assignments.
Next Steps