### Installation and Authentication Source: https://context7.com/umami-software/api-client/llms.txt Guides on how to install the Umami API Client and authenticate using environment variables or manual configuration. ```APIDOC ## Installation and Authentication ### Basic Setup with Environment Variables This method uses environment variables to configure the client. **Environment Variables:** - `UMAMI_API_CLIENT_USER_ID` - `UMAMI_API_CLIENT_SECRET` - `UMAMI_API_CLIENT_ENDPOINT` - `UMAMI_API_KEY` #### Request Example ```javascript import { getClient } from '@umami/api-client'; const client = getClient(); // Verify authentication const { ok, data, status, error } = await client.verify(); if (ok) { console.log('Authenticated successfully'); } else { console.error(`Authentication failed: ${error.message}`); } ``` ### Manual Configuration This method allows for direct configuration of the client instance. #### Parameters - **apiEndpoint** (string) - Required - The base URL of the Umami API. - **apiKey** (string) - Optional - The API key for authentication. - **userId** (string) - Optional - The user ID for authentication. - **secret** (string) - Optional - The secret for authentication. #### Request Example ```javascript import { UmamiApiClient } from '@umami/api-client'; const client = new UmamiApiClient({ apiEndpoint: 'https://analytics.example.com/api', apiKey: 'your-api-key-here', userId: 'user-uuid', secret: 'your-secret' }); // Login with credentials const loginResult = await client.login('username', 'password'); if (loginResult.ok) { console.log('Logged in:', loginResult.data.token); } // Get current user info const me = await client.getMe(); console.log('Current user:', me.data.username); ``` ``` -------------------------------- ### Website Management: Create, Update, and Get Source: https://context7.com/umami-software/api-client/llms.txt Demonstrates the creation of a new website, updating its settings, and retrieving its details using the API client. Requires website name and domain for creation. ```javascript // Create a new website const newSite = await client.createWebsite({ name: 'My Product Site', domain: 'product.example.com' }); if (newSite.ok) { console.log('Website created:', newSite.data.id); const websiteId = newSite.data.id; // Update website settings await client.updateWebsite(websiteId, { name: 'My Product Site (Production)', domain: 'product.example.com', shareId: newSite.data.shareId }); // Get website details const site = await client.getWebsite(websiteId); console.log('Website:', site.data.name, site.data.domain); } ``` -------------------------------- ### Execute API Routes Dynamically with Umami Client Source: https://context7.com/umami-software/api-client/llms.txt This snippet demonstrates how to execute any Umami API route dynamically using the `executeRoute` method. It shows examples for both GET and POST requests, including passing parameters and handling responses. Ensure the client is initialized before use. ```javascript // Execute any API route dynamically const result = await client.executeRoute( 'websites/my-website-id/stats', 'GET', { startAt: Date.now() - 7 * 24 * 60 * 60 * 1000, endAt: Date.now() } ); if (result.ok) { console.log('Route result:', result.data); } else { console.error('Route error:', result.error.message); } // Execute POST route const postResult = await client.executeRoute( 'teams', 'POST', { name: 'New Team', domain: 'team.example.com' } ); ``` -------------------------------- ### Website Management: List, Search, and Filter Source: https://context7.com/umami-software/api-client/llms.txt Provides examples for listing websites with options for pagination, sorting, and searching. It also shows how to retrieve websites associated with the current user, optionally including team data. ```javascript // Get all websites with pagination const websites = await client.getWebsites({ page: 1, pageSize: 20, orderBy: 'name', sortDescending: false, search: 'product' }); if (websites.ok) { console.log(`Found ${websites.data.count} websites`); websites.data.data.forEach(site => { console.log(`- ${site.name} (${site.domain}) - ${site.id}`); }); } // Get websites for current user const myWebsites = await client.getMyWebsites({ includeTeams: true }); ``` -------------------------------- ### Real-Time Analytics Source: https://context7.com/umami-software/api-client/llms.txt Get real-time website analytics, including the number of currently active visitors and a stream of recent pageviews and events. ```APIDOC ## GET /websites/{websiteId}/active ### Description Retrieves the number of currently active visitors on a website. ### Method GET ### Endpoint `/websites/{websiteId}/active` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. ### Request Example ```javascript const active = await client.getWebsiteActive(websiteId); ``` ### Response #### Success Response (200) - **x** (integer) - The number of active visitors. #### Response Example ```json { "ok": true, "data": { "x": 50 } } ``` ## GET /websites/{websiteId}/realtime ### Description Retrieves real-time data for a website, including recent pageviews and events. ### Method GET ### Endpoint `/websites/{websiteId}/realtime` ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website. #### Query Parameters - **startAt** (integer) - Required - The start of the time range (Unix timestamp), typically used to define the lookback period for recent data. ### Request Example ```javascript const realtime = await client.getRealtime(websiteId, { startAt: Date.now() - 5 * 60 * 1000 // Last 5 minutes }); ``` ### Response #### Success Response (200) - **pageviews** (array) - An array of recent pageview objects. - **events** (array) - An array of recent event objects. - **timestamp** (integer) - The timestamp of the last activity. #### Response Example ```json { "ok": true, "data": { "pageviews": [...], "events": [...], "timestamp": 1678886400000 } } ``` ``` -------------------------------- ### Get Current User's Websites with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Retrieves a list of websites associated with the current user, with options to include team websites and pagination. Useful for displaying accessible websites to the logged-in user. ```javascript // Get my websites const myWebsites = await client.getMyWebsites({ includeTeams: true, page: 1, pageSize: 20 }); ``` -------------------------------- ### Dynamic Route Execution Source: https://context7.com/umami-software/api-client/llms.txt Execute any Umami API route dynamically using the `executeRoute` method. This allows for flexible interaction with various endpoints, including GET and POST requests, with support for query parameters and request bodies. ```APIDOC ## Execute Any API Route Dynamically ### Description Executes a specified API route with a given HTTP method, optional query parameters, and an optional request body. ### Method `client.executeRoute(route, method, params?, body?) ### Parameters * `route` (string) - The API endpoint path (e.g., 'websites/my-website-id/stats'). * `method` (string) - The HTTP method (e.g., 'GET', 'POST'). * `params` (object, optional) - Query parameters for the request. * `body` (object, optional) - The request body for POST, PUT, etc. ### Request Example (GET) ```javascript const result = await client.executeRoute( 'websites/my-website-id/stats', 'GET', { startAt: Date.now() - 7 * 24 * 60 * 60 * 1000, endAt: Date.now() } ); ``` ### Request Example (POST) ```javascript const postResult = await client.executeRoute( 'teams', 'POST', {}, { name: 'New Team', domain: 'team.example.com' } ); ``` ### Response * `ok` (boolean) - Indicates if the request was successful. * `data` (object) - The response data if `ok` is true. * `error` (object) - The error object if `ok` is false. ``` -------------------------------- ### API Client Configuration and Custom Headers Source: https://context7.com/umami-software/api-client/llms.txt Configure the Umami API Client with your API endpoint and key. You can dynamically update the API endpoint and make requests with custom headers using the `get`, `post`, `put`, and `del` methods. ```APIDOC ## API Client Configuration and Custom Headers ### Description Initialize the `UmamiApiClient` with your API endpoint and key. The client can be configured to use custom headers for requests and provides direct methods for common HTTP verbs. ### Initialization ```javascript import { UmamiApiClient } from '@umami-api-client'; const client = new UmamiApiClient({ apiEndpoint: 'https://analytics.example.com/api', apiKey: 'your-api-key' }); ``` ### Configuration Methods * `client.setApiEndPoint(endpoint: string)` - Dynamically change the API endpoint. * `client.setSecret(secret: string)` - Update the secret for token generation. ### Making Requests with Custom Headers ```javascript const result = await client.get('websites', {}, {'X-Custom-Header': 'custom-value'} ); ``` ### Direct HTTP Method Access * `client.get(route: string, params?: object, headers?: object)` * `client.post(route: string, body: object, headers?: object)` * `client.put(route: string, body: object, headers?: object)` * `client.del(route: string, params?: object, headers?: object)` ### Example Usage ```javascript // Make a GET request with custom headers await client.get('websites', {}, { 'X-Custom-Header': 'custom-value' }); // Make a POST request await client.post('custom-endpoint', { data: 'value' }); // Make a PUT request await client.put('custom-endpoint', { data: 'updated' }); // Make a DELETE request await client.del('custom-endpoint', { id: '123' }); ``` ``` -------------------------------- ### Get User's Websites with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Retrieves the list of websites associated with a specific user, supporting pagination. This allows for managing user permissions across different websites. Requires the user ID and pagination parameters. ```javascript // Get user's websites const userWebsites = await client.getUserWebsites(userId, { page: 1, pageSize: 10 }); ``` -------------------------------- ### Configure Umami API Client with Custom Headers Source: https://context7.com/umami-software/api-client/llms.txt This section shows how to initialize the Umami API Client with a custom API endpoint and API key. It also demonstrates how to dynamically change the API endpoint, update the secret for token generation, and make requests with custom headers using direct HTTP method access (get, post, put, del). ```javascript import { UmamiApiClient } from '@umami/api-client'; const client = new UmamiApiClient({ apiEndpoint: 'https://analytics.example.com/api', apiKey: 'your-api-key' }); // Change API endpoint dynamically client.setApiEndPoint('https://new-analytics.example.com/api'); // Update secret for token generation client.setSecret('new-secret-key'); // Make requests with custom headers const result = await client.get('websites', {}, { 'X-Custom-Header': 'custom-value' }); // Direct HTTP method access await client.post('custom-endpoint', { data: 'value' }); await client.put('custom-endpoint', { data: 'updated' }); await client.del('custom-endpoint', { id: '123' }); ``` -------------------------------- ### Create, Update, Get, and Delete Reports using API Client Source: https://context7.com/umami-software/api-client/llms.txt Covers the lifecycle management of custom reports, including creating a new report with specified parameters, updating an existing report's configuration, retrieving report details, and deleting a report. Also shows how to list all available reports and retrieve reports for a specific website. ```javascript // Create a custom report const report = await client.createReport({ websiteId: 'website-uuid', name: 'Monthly Traffic Report', type: 'insights', description: 'Detailed traffic analysis for monthly review', parameters: { fields: [{ name: 'url', type: 'string', label: 'Page URL' }], filters: [], groups: [{ name: 'country', type: 'string' }] } }); if (report.ok) { const reportId = report.data.id; // Update report await client.updateReport(reportId, { websiteId: 'website-uuid', type: 'insights', name: 'Updated Monthly Traffic Report', description: 'Updated description', parameters: JSON.stringify({ updated: true }) }); // Get report const reportData = await client.getReport(reportId); console.log('Report:', reportData.data); // Delete report await client.deleteReport(reportId); } // List all reports const reports = await client.getReports({ page: 1, pageSize: 20 }); // Get website reports const websiteReports = await client.getWebsiteReports('website-uuid'); ``` -------------------------------- ### Get Specific Session Details with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Fetches detailed information for a single session, identified by its website ID and session ID. The response includes all available data points for that specific session. ```javascript const websiteId = 'website-uuid'; const sessionId = 'session-uuid'; // Get specific session const session = await client.getWebsiteSession(websiteId, sessionId); if (session.ok) { console.log('Session:', session.data); } ``` -------------------------------- ### Get User Usage Statistics with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Fetches usage statistics for a specific user within a given date range. This helps in monitoring user activity and resource consumption. It requires the user ID and start/end dates. ```javascript // Get user usage statistics const userId = 'user-uuid'; const usage = await client.getUserUsage(userId, { startAt: Date.now() - 30 * 24 * 60 * 60 * 1000, endAt: Date.now() }); ``` -------------------------------- ### Get Website Sessions with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Retrieves all sessions for a given website within a specified date range. It handles the response, logs the total session count, and iterates through each session to display its details. This function requires the website ID and optional start/end dates. ```javascript const websiteId = 'website-uuid'; // Get all sessions const sessions = await client.getWebsiteSessions(websiteId, { startAt: '2024-01-01', endAt: '2024-01-31' }); if (sessions.ok) { console.log(`Total sessions: ${sessions.data.count}`); sessions.data.data.forEach(session => { console.log(`Session ${session.id}:`); console.log(` Device: ${session.device} | OS: ${session.os} | Browser: ${session.browser}`); console.log(` Location: ${session.city}, ${session.country}`); console.log(` Views: ${session.views} | Visits: ${session.visits}`); console.log(` Duration: ${session.firstAt} to ${session.lastAt}`); }); } ``` -------------------------------- ### Get Real-Time Analytics (JavaScript) Source: https://context7.com/umami-software/api-client/llms.txt Fetches real-time analytics data for a given website, including the number of currently active visitors and a stream of recent pageviews and events. It requires a website ID and a time range for the data stream. ```javascript const websiteId = 'website-uuid'; // Get currently active visitors const active = await client.getWebsiteActive(websiteId); if (active.ok) { console.log('Active visitors:', active.data.x); } // Get real-time data stream const realtime = await client.getRealtime(websiteId, { startAt: Date.now() - 5 * 60 * 1000 // Last 5 minutes }); if (realtime.ok) { console.log('Recent pageviews:', realtime.data.pageviews.length); console.log('Recent events:', realtime.data.events.length); console.log('Timestamp:', new Date(realtime.data.timestamp)); } ``` -------------------------------- ### Manage Team Members and Delete Teams using API Client Source: https://context7.com/umami-software/api-client/llms.txt Provides code examples for retrieving team details, fetching team members with pagination, adding users to a team, updating member roles, removing users, and ultimately deleting the entire team. Requires a valid team ID and user IDs. ```javascript const teamId = 'team-uuid'; // Get team details const team = await client.getTeam(teamId); console.log('Team:', team.data.name); // Get team members const members = await client.getTeamUsers(teamId, { page: 1, pageSize: 50 }); if (members.ok) { console.log(`Team has ${members.data.count} members`); members.data.data.forEach(user => { console.log(`- ${user.username}`); }); } // Add user to team const newMember = await client.createTeamUser(teamId, { userId: 'user-uuid', role: 'member' }); // Update team member role await client.updateTeamMember(teamId, 'user-uuid', { role: 'admin' }); // Remove user from team await client.deleteTeamUser(teamId, 'user-uuid'); // Delete team await client.deleteTeam(teamId); ``` -------------------------------- ### Get Website Session Statistics with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Fetches statistics for website sessions, allowing filtering by country and device. It requires the website ID and date range, along with optional country and device filters. The output includes aggregated session data based on the provided criteria. ```javascript const websiteId = 'website-uuid'; // Get session statistics const sessionStats = await client.getWebsiteSessionStats(websiteId, { startAt: '2024-01-01', endAt: '2024-01-31', country: 'US', device: 'desktop' }); if (sessionStats.ok) { console.log('Session stats:', sessionStats.data); } ``` -------------------------------- ### Get Event Data Fields, Values, and Statistics (JavaScript) Source: https://context7.com/umami-software/api-client/llms.txt Provides methods to retrieve detailed information about events, including all event names and properties, statistics (total events, properties, records), specific property values for an event, and a list of all event data fields. Requires website ID and date range. ```javascript const websiteId = 'website-uuid'; const startAt = Date.now() - 30 * 24 * 60 * 60 * 1000; const endAt = Date.now(); // Get all event names and properties const eventDataEvents = await client.getEventDataEvents(websiteId, { startAt, endAt, event: 'purchase' }); // Get event data statistics const eventStats = await client.getEventDataStats(websiteId, { startAt, endAt }); if (eventStats.ok) { console.log(`Total events: ${eventStats.data.events}`); console.log(`Total properties: ${eventStats.data.properties}`); console.log(`Total records: ${eventStats.data.records}`); } // Get specific property values const values = await client.getEventDataValues(websiteId, { startAt, endAt, eventName: 'purchase', propertyName: 'product_category' }); if (values.ok) { values.data.forEach(val => { console.log(`${val.value}: ${val.total} occurrences`); }); } // Get all event data fields const fields = await client.getEventDataFields(websiteId, { startAt, endAt }); ``` -------------------------------- ### Get Current User Profile with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Retrieves the profile information for the currently authenticated user. This function does not require any parameters and returns details such as the username. ```javascript // Get current user profile const me = await client.getMe(); console.log('Logged in as:', me.data.username); ``` -------------------------------- ### Initialize API Client with Manual Configuration Source: https://context7.com/umami-software/api-client/llms.txt Initializes the Umami API client by manually providing configuration details such as API endpoint, API key, User ID, and Secret. Includes logging in with credentials and retrieving user information. ```javascript import { UmamiApiClient } from '@umami/api-client'; const client = new UmamiApiClient({ apiEndpoint: 'https://analytics.example.com/api', apiKey: 'your-api-key-here', userId: 'user-uuid', secret: 'your-secret' }); // Login with credentials const loginResult = await client.login('username', 'password'); if (loginResult.ok) { console.log('Logged in:', loginResult.data.token); } // Get current user info const me = await client.getMe(); console.log('Current user:', me.data.username); ``` -------------------------------- ### Create, Update, and List Teams using API Client Source: https://context7.com/umami-software/api-client/llms.txt Demonstrates how to create a new team, update an existing team's details, join a team using an access code, and list all teams with search and pagination parameters. Requires an authenticated client instance. ```javascript const team = await client.createTeam({ name: 'Marketing Team', domain: 'marketing.example.com' }); if (team.ok) { console.log('Team created:', team.data.id); const teamId = team.data.id; // Update team await client.updateTeam(teamId, { name: 'Marketing & Growth Team', accessCode: 'new-access-code-123' }); // Join team with access code const joinResult = await client.joinTeam({ accessCode: 'team-access-code' }); } // List all teams const teams = await client.getTeams({ search: 'marketing', page: 1, pageSize: 20 }); ``` -------------------------------- ### Get User's Teams with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Fetches the list of teams a specific user belongs to. This is useful for understanding team associations and permissions. Requires the user ID. ```javascript // Get user's teams const userTeams = await client.getUserTeams(userId); ``` -------------------------------- ### Initialize API Client with Environment Variables Source: https://context7.com/umami-software/api-client/llms.txt Initializes the Umami API client using environment variables for configuration (UserID, Secret, Endpoint, API Key). It then verifies the authentication status. ```javascript import { getClient } from '@umami/api-client'; // Uses environment variables: // UMAMI_API_CLIENT_USER_ID // UMAMI_API_CLIENT_SECRET // UMAMI_API_CLIENT_ENDPOINT // UMAMI_API_KEY const client = getClient(); // Verify authentication const { ok, data, status, error } = await client.verify(); if (ok) { console.log('Authenticated successfully'); } else { console.error(`Authentication failed: ${error.message}`); } ``` -------------------------------- ### Get Current User's Teams with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Fetches the list of teams the current user is a member of. This helps in managing user access and permissions within teams. ```javascript // Get my teams const myTeams = await client.getMyTeams(); ``` -------------------------------- ### Manage Team Websites and Transfer Ownership using API Client Source: https://context7.com/umami-software/api-client/llms.txt Illustrates how to retrieve a list of websites associated with a team, add a new website to a team, remove a website from a team, and transfer website ownership either to another team or a specific user. Requires team and website identifiers. ```javascript const teamId = 'team-uuid'; // Get team websites const teamWebsites = await client.getTeamWebsites(teamId, { page: 1, pageSize: 20 }); if (teamWebsites.ok) { console.log(`Team has ${teamWebsites.data.count} websites`); } // Add website to team const teamWebsite = await client.createTeamWebsite(teamId, { name: 'Team Marketing Site', domain: 'marketing.example.com', shareId: '' }); // Remove website from team await client.deleteTeamWebsite(teamId, 'website-uuid'); // Transfer website ownership await client.transferWebsite('website-uuid', { teamId: 'new-team-uuid' }); // Or transfer to user await client.transferWebsite('website-uuid', { userId: 'user-uuid' }); ``` -------------------------------- ### Create User with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Creates a new user account with a specified username, password, and role. The function returns the details of the newly created user, including their ID. This is the first step in user management. ```javascript // Create a new user const newUser = await client.createUser({ username: 'john.doe', password: 'secure-password-123', role: 'user' }); if (newUser.ok) { console.log('User created:', newUser.data.id, newUser.data.username); const userId = newUser.data.id; // Update user await client.updateUser(userId, { username: 'john.doe.updated', password: 'new-password-456' }); // Get user details const user = await client.getUser(userId); console.log('User:', user.data); } ``` -------------------------------- ### Website Management API Source: https://context7.com/umami-software/api-client/llms.txt Endpoints for managing websites, including creation, updates, retrieval, and deletion. ```APIDOC ## Website Management ### Creating and Managing Websites #### POST /websites Creates a new website. ##### Request Body - **name** (string) - Required - The name of the website. - **domain** (string) - Required - The domain of the website. ##### Request Example ```javascript const newSite = await client.createWebsite({ name: 'My Product Site', domain: 'product.example.com' }); if (newSite.ok) { console.log('Website created:', newSite.data.id); const websiteId = newSite.data.id; // Update website settings await client.updateWebsite(websiteId, { name: 'My Product Site (Production)', domain: 'product.example.com', shareId: newSite.data.shareId }); // Get website details const site = await client.getWebsite(websiteId); console.log('Website:', site.data.name, site.data.domain); } ``` #### PUT /websites/:id Updates an existing website. ##### Parameters - **id** (string) - Required - The ID of the website to update. ##### Request Body - **name** (string) - Optional - The new name of the website. - **domain** (string) - Optional - The new domain of the website. - **shareId** (string) - Optional - The share ID for the website. #### GET /websites/:id Retrieves details for a specific website. ##### Parameters - **id** (string) - Required - The ID of the website to retrieve. ### Listing Websites with Search and Pagination #### GET /websites Retrieves a list of websites with support for search and pagination. ##### Query Parameters - **page** (number) - Optional - The page number for pagination. - **pageSize** (number) - Optional - The number of results per page. - **orderBy** (string) - Optional - The field to order results by (e.g., 'name'). - **sortDescending** (boolean) - Optional - Whether to sort in descending order. - **search** (string) - Optional - A search term to filter websites by name or domain. #### GET /user/websites Retrieves websites associated with the current user. ##### Query Parameters - **includeTeams** (boolean) - Optional - Whether to include websites belonging to teams the user is part of. #### Response Example (GET /websites) ```json { "ok": true, "data": { "data": [ { "id": "website-uuid", "name": "My Product Site", "domain": "product.example.com", "createdAt": "2024-01-01T10:00:00Z", "updatedAt": "2024-01-01T10:00:00Z", "shareId": "share-uuid" } ], "count": 1 } } ``` ### Resetting and Deleting Websites #### POST /websites/:id/reset Resets all analytics data for a specific website. ##### Parameters - **id** (string) - Required - The ID of the website to reset. #### DELETE /websites/:id Deletes a website permanently. ##### Parameters - **id** (string) - Required - The ID of the website to delete. #### Request Example (DELETE /websites/:id) ```javascript const websiteId = 'website-uuid'; // Reset all analytics data const resetResult = await client.resetWebsite(websiteId); if (resetResult.ok) { console.log('Website data reset successfully'); } // Delete website permanently const deleteResult = await client.deleteWebsite(websiteId); if (deleteResult.ok) { console.log('Website deleted'); } else { console.error('Delete failed:', deleteResult.error.message); } ``` ``` -------------------------------- ### User Management Source: https://context7.com/umami-software/api-client/llms.txt APIs for creating, retrieving, updating, and deleting users, as well as querying user lists and usage statistics. ```APIDOC ## User Management ### Create User Creates a new user with the specified username, password, and role. ### Method POST ### Endpoint `/users` ### Parameters #### Request Body - **username** (string) - Required - The username for the new user. - **password** (string) - Required - The password for the new user. - **role** (string) - Required - The role of the user (e.g., 'user', 'admin'). ### Request Example ```javascript const newUser = await client.createUser({ username: 'john.doe', password: 'secure-password-123', role: 'user' }); ``` ### Response #### Success Response (201) - **id** (string) - The unique identifier for the newly created user. - **username** (string) - The username of the new user. #### Response Example ```json { "ok": true, "data": { "id": "user-uuid", "username": "john.doe" } } ``` ### Update User Updates an existing user's information, including username and password. ### Method PUT ### Endpoint `/users/{userId}` ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user to update. #### Request Body - **username** (string) - Optional - The updated username. - **password** (string) - Optional - The updated password. ### Request Example ```javascript const userId = 'user-uuid'; await client.updateUser(userId, { username: 'john.doe.updated', password: 'new-password-456' }); ``` ### Get User Details Retrieves the details of a specific user by their ID. ### Method GET ### Endpoint `/users/{userId}` ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user. ### Request Example ```javascript const userId = 'user-uuid'; const user = await client.getUser(userId); ``` ### Response #### Success Response (200) - **data** (object) - An object containing the user's details. - **id** (string) - The user's ID. - **username** (string) - The user's username. - **isAdmin** (boolean) - Indicates if the user is an administrator. #### Response Example ```json { "ok": true, "data": { "id": "user-uuid", "username": "john.doe", "isAdmin": false } } ``` ### List All Users Retrieves a list of all users, with options for searching, pagination, and sorting. ### Method GET ### Endpoint `/users` ### Parameters #### Query Parameters - **search** (string) - Optional - Search term to filter users by username. - **page** (integer) - Optional - The page number for pagination. - **pageSize** (integer) - Optional - The number of users per page. - **orderBy** (string) - Optional - Field to sort users by (e.g., 'username'). - **sortDescending** (boolean) - Optional - Whether to sort in descending order. ### Request Example ```javascript const users = await client.getUsers({ search: 'john', page: 1, pageSize: 50, orderBy: 'username', sortDescending: false }); ``` ### Response #### Success Response (200) - **count** (integer) - The total number of users matching the query. - **data** (array) - An array of user objects. - **username** (string) - The user's username. - **isAdmin** (boolean) - Indicates if the user is an administrator. #### Response Example ```json { "ok": true, "data": { "count": 10, "data": [ { "username": "john.doe", "isAdmin": false } ] } } ``` ### Get User Usage Statistics Retrieves usage statistics for a specific user within a given date range. ### Method GET ### Endpoint `/users/{userId}/usage` ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user. #### Query Parameters - **startAt** (number/string) - Required - The start timestamp or date string. - **endAt** (number/string) - Required - The end timestamp or date string. ### Request Example ```javascript const userId = 'user-uuid'; const usage = await client.getUserUsage(userId, { startAt: Date.now() - 30 * 24 * 60 * 60 * 1000, // 30 days ago endAt: Date.now() }); ``` ### Get User's Websites Retrieves a list of websites associated with a specific user, with pagination options. ### Method GET ### Endpoint `/users/{userId}/websites` ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user. #### Query Parameters - **page** (integer) - Optional - The page number for pagination. - **pageSize** (integer) - Optional - The number of websites per page. ### Request Example ```javascript const userId = 'user-uuid'; const userWebsites = await client.getUserWebsites(userId, { page: 1, pageSize: 10 }); ``` ### Get User's Teams Retrieves a list of teams that a specific user is a member of. ### Method GET ### Endpoint `/users/{userId}/teams` ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user. ### Request Example ```javascript const userId = 'user-uuid'; const userTeams = await client.getUserTeams(userId); ``` ### Delete User Deletes a user by their ID. ### Method DELETE ### Endpoint `/users/{userId}` ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user to delete. ### Request Example ```javascript const userId = 'user-uuid'; await client.deleteUser(userId); ``` ``` -------------------------------- ### Team Website Management API Source: https://context7.com/umami-software/api-client/llms.txt Endpoints for managing websites associated with a team, including adding, removing, and transferring ownership. ```APIDOC ## GET /api/teams/{id}/websites ### Description Retrieves a list of websites associated with a team. ### Method GET ### Endpoint /api/teams/{id}/websites ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the team. #### Query Parameters - **page** (integer) - Optional - The page number for pagination. - **pageSize** (integer) - Optional - The number of results per page. ### Response #### Success Response (200) - **data** (array) - An array of website objects associated with the team. - **count** (integer) - The total number of websites. #### Response Example ```json { "ok": true, "data": [ { "id": "website-uuid", "name": "Team Marketing Site", "domain": "marketing.example.com" } ], "count": 1 } ``` ## POST /api/teams/{id}/websites ### Description Adds a website to a team. ### Method POST ### Endpoint /api/teams/{id}/websites ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the team. #### Request Body - **name** (string) - Required - The name of the website. - **domain** (string) - Required - The domain of the website. - **shareId** (string) - Optional - Share ID for the website. ### Request Example ```json { "name": "Team Marketing Site", "domain": "marketing.example.com", "shareId": "" } ``` ## DELETE /api/teams/{id}/websites/{websiteId} ### Description Removes a website from a team. ### Method DELETE ### Endpoint /api/teams/{id}/websites/{websiteId} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the team. - **websiteId** (string) - Required - The ID of the website to remove. ## POST /api/websites/{websiteId}/transfer ### Description Transfers website ownership to another team or user. ### Method POST ### Endpoint /api/websites/{websiteId}/transfer ### Parameters #### Path Parameters - **websiteId** (string) - Required - The ID of the website to transfer. #### Request Body - **teamId** (string) - Optional - The ID of the team to transfer ownership to. - **userId** (string) - Optional - The ID of the user to transfer ownership to. ### Request Example (Transfer to Team) ```json { "teamId": "new-team-uuid" } ``` ### Request Example (Transfer to User) ```json { "userId": "user-uuid" } ``` ``` -------------------------------- ### Website Management: Reset and Delete Source: https://context7.com/umami-software/api-client/llms.txt Shows how to reset all analytics data for a specific website and how to permanently delete a website using its ID. These are destructive operations. ```javascript const websiteId = 'website-uuid'; // Reset all analytics data const resetResult = await client.resetWebsite(websiteId); if (resetResult.ok) { console.log('Website data reset successfully'); } // Delete website permanently const deleteResult = await client.deleteWebsite(websiteId); if (deleteResult.ok) { console.log('Website deleted'); } else { console.error('Delete failed:', deleteResult.error.message); } ``` -------------------------------- ### Get Session Custom Data with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Fetches custom data associated with a specific session. This function requires the website ID and session ID. It iterates through the custom data entries, displaying their keys, types, and values. ```javascript const websiteId = 'website-uuid'; const sessionId = 'session-uuid'; // Get session custom data const sessionData = await client.getSessionData(websiteId, sessionId); if (sessionData.ok) { sessionData.data.data.forEach(data => { console.log(`${data.dataKey} (${data.dataType}): ${data.stringValue || data.numberValue}`); }); } ``` -------------------------------- ### Team Management API Source: https://context7.com/umami-software/api-client/llms.txt Endpoints for creating, updating, joining, and listing teams. ```APIDOC ## POST /api/teams ### Description Creates a new team. ### Method POST ### Endpoint /api/teams ### Parameters #### Request Body - **name** (string) - Required - The name of the team. - **domain** (string) - Optional - The domain associated with the team. ### Request Example ```json { "name": "Marketing Team", "domain": "marketing.example.com" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created team. #### Response Example ```json { "ok": true, "data": { "id": "team-uuid" } } ``` ## PUT /api/teams/{id} ### Description Updates an existing team. ### Method PUT ### Endpoint /api/teams/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the team to update. #### Request Body - **name** (string) - Optional - The new name for the team. - **accessCode** (string) - Optional - A new access code for the team. ### Request Example ```json { "name": "Marketing & Growth Team", "accessCode": "new-access-code-123" } ``` ## POST /api/teams/join ### Description Joins an existing team using an access code. ### Method POST ### Endpoint /api/teams/join ### Parameters #### Request Body - **accessCode** (string) - Required - The access code for the team. ### Request Example ```json { "accessCode": "team-access-code" } ``` ## GET /api/teams ### Description Retrieves a list of teams. ### Method GET ### Endpoint /api/teams ### Parameters #### Query Parameters - **search** (string) - Optional - Search query to filter teams by name. - **page** (integer) - Optional - The page number for pagination. - **pageSize** (integer) - Optional - The number of results per page. ### Response #### Success Response (200) - **data** (array) - An array of team objects. - **count** (integer) - The total number of teams matching the query. #### Response Example ```json { "ok": true, "data": [ { "id": "team-uuid", "name": "Marketing Team" } ], "count": 1 } ``` ``` -------------------------------- ### Get All Session Data Properties with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Retrieves a list of all available session data properties and the total number of sessions associated with each property within a specified date range. This is useful for understanding the types of custom data being collected. ```javascript const websiteId = 'website-uuid'; const startAt = Date.now() - 7 * 24 * 60 * 60 * 1000; const endAt = Date.now(); // Get all session properties const properties = await client.getSessionDataProperties(websiteId, { startAt, endAt }); if (properties.ok) { properties.data.forEach(prop => { console.log(`Property: ${prop.propertyName} - ${prop.total} sessions`); }); } ``` -------------------------------- ### Get Session Activity Timeline with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Retrieves the activity timeline for a specific session, showing the sequence of events or pageviews. This function requires the website ID and session ID, along with an optional date range to filter activities. ```javascript const websiteId = 'website-uuid'; const sessionId = 'session-uuid'; // Get session activity timeline const activity = await client.getSessionActivity(websiteId, sessionId, { startAt: '2024-01-01', endAt: '2024-01-31' }); if (activity.ok) { console.log('Activity timeline:'); activity.data.data.forEach(act => { console.log(`${act.createdAt}: ${act.eventName || 'pageview'} - ${act.urlPath}`); }); } ``` -------------------------------- ### Get Weekly Session Heatmap with Umami API Client Source: https://context7.com/umami-software/api-client/llms.txt Retrieves weekly session data for a website, typically used for heatmap visualizations. This function requires the website ID and a date range, returning structured data that can represent session activity over time. ```javascript const websiteId = 'website-uuid'; // Get weekly session heatmap const weekly = await client.getWebsiteSessionsWeekly(websiteId, { startAt: '2024-01-01', endAt: '2024-01-31' }); ``` -------------------------------- ### Current User Operations Source: https://context7.com/umami-software/api-client/llms.txt APIs for interacting with the currently authenticated user's profile, websites, teams, and password. ```APIDOC ## Current User Operations ### Get Current User Profile Retrieves the profile information of the currently authenticated user. ### Method GET ### Endpoint `/me` ### Request Example ```javascript const me = await client.getMe(); console.log('Logged in as:', me.data.username); ``` ### Response #### Success Response (200) - **username** (string) - The username of the current user. #### Response Example ```json { "ok": true, "data": { "username": "current_user" } } ``` ### Get My Websites Retrieves a list of websites accessible by the current user, with options to include teams and pagination. ### Method GET ### Endpoint `/me/websites` ### Parameters #### Query Parameters - **includeTeams** (boolean) - Optional - Whether to include websites associated with the user's teams. - **page** (integer) - Optional - The page number for pagination. - **pageSize** (integer) - Optional - The number of websites per page. ### Request Example ```javascript const myWebsites = await client.getMyWebsites({ includeTeams: true, page: 1, pageSize: 20 }); ``` ### Get My Teams Retrieves a list of teams that the current user is a member of. ### Method GET ### Endpoint `/me/teams` ### Request Example ```javascript const myTeams = await client.getMyTeams(); ``` ### Update My Password Updates the password for the currently authenticated user. ### Method PUT ### Endpoint `/me/password` ### Parameters #### Request Body - **currentPassword** (string) - Required - The current password of the user. - **newPassword** (string) - Required - The new password for the user. ### Request Example ```javascript const passwordResult = await client.updateMyPassword({ currentPassword: 'old-password', newPassword: 'new-secure-password' }); if (passwordResult.ok) { console.log('Password updated successfully'); } ``` ### Response #### Success Response (200) Indicates that the password was updated successfully. #### Response Example ```json { "ok": true } ``` ```