Posts: Get visitor data via Umami API

Published 2026-04-06 08:36 798 words 4 min read

Detailed explanation of how to obtain website visitor data through Umami API, including the acquisition of API keys for Umami Cloud and self-hosted versions, sharing link Token authentication methods, and the invocation, parameter filtering, and differences in data structure between new and old versions of the /api/websites/:websiteId/stats interface, to fully implement programmatic retrieval of page views, unique visitors, and other data.

Translated by AI model Qwen/Qwen3-8B.

Source Language: Simplified Chinese, Target Language: english, Translation Time: 2026-05-01 02:37

.

AI translation is for reference only. Accuracy is not guaranteed, please refer to the original text.

Authentication

Umami API requires authentication, which can be done using the user's API key or using the API key from the website share x-umami-share-token.

Getting the User's API Key

Getting API Key for Umami Cloud Users

If you are a Umami Cloud user, you need to generate the API key in the Umami Cloud console.

Umami Cloud API Key Documentation

Getting API Key for Umami Self-Hosted Users

If your Token is publicly accessible, it is recommended to transfer the website to a team and add a user with only access permissions. Use this user's Token for authentication.

If you are a Umami Self-Hosted user, you need to send the following request body to POST /api/auth/login,

{
  "username": "your-username",
  "password": "your-password"
}

If the login is successful, you should receive the following response, note down token.

{
  "token": "eyTMjU2IiwiY...4Q0JDLUhWxnIjoiUE_A",
  "user": {
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "username": "admin",
    "role": "admin",
    "createdAt": "2000-00-00T00:00:00.000Z",
    "isAdmin": true
  }
}

After enabling the share link for the website, you will receive a share link, like:

https://u.ksable.top/share/gR1PdRDiutFusWn6

Add api to the beginning of the pathname of the link, like:

https://u.ksable.top/api/share/gR1PdRDiutFusWn6

Then open it, and you will receive the following response, note down token.

{
  "websiteId": "a-b-c-d",
  "token": "a.b.c"
}

Adding Authentication to the Interface

To add authentication to the interface, you need to include the authorization field in the request header, with the value Bearer {token}.

GET /api/*
Authorization: Bearer a.b.c

If you obtained token from the share link, you need to add the x-umami-share-token field in the request header, with the value token.

GET /api/*
x-umami-share-token: a.b.c

Retrieving Visitor Data

API Endpoint

GET /api/websites/:websiteId/stats

Parameters

ParameterParameter TypeDescription
startAtnumberStart time, in milliseconds
endAtnumberEnd time, in milliseconds
filtersobjectFilter parameters

Example:

GET /api/websites/:websiteId/stats
Authorization: Bearer a.b.c

You will receive the following response,

{
  "pageviews": 15171,
  "visitors": 4415,
  "visits": 5680,
  "bounces": 3567,
  "totaltime": 809968,
  "comparison": {
    "pageviews": 38675,
    "visitors": 10568,
    "visits": 14595,
    "bounces": 9364,
    "totaltime": 2182387
  }
}

Where pageviews is the number of page views, and visitors is the number of unique visitors. Usually, only these two metrics are needed.

Descriptions of some fields are as follows:

FieldDescription
pageviewsPage clicks
visitorsNumber of unique visitors
visitsNumber of unique visits
bouncesNumber of visitors who only viewed a single page
totaltimeTime spent on the website
Note: If you are using an older version of Umami, the returned data structure may differ from the new version.

The data structure returned by the old version of Umami is as follows:

{
  "pageviews": {
    "value": 15171
  },
  "visitors": {
    "value": 4415
  },
  "visits": {
    "value": 5680
  },
  "bounces": {
    "value": 3567
  },
  "totaltime": {
    "value": 809968
  }
}

You can add the filters parameter to filter the data as needed. For example, path=/post/bian-jian-tong-guo-api-huo-qu-umami-fang-ke-shu-ju

GET /api/websites/:websiteId/stats?path=/post/bian-jian-tong-guo-api-huo-qu-umami-fang-ke-shu-ju

Will return visitor data for the path /post/bian-jian-tong-guo-api-huo-qu-umami-fang-ke-shu-ju.

Some Filter Parameters
ParameterTypeDescription
pathstringURL path
referrerstringReferral source
titlestringPage title
querystringQuery parameter
browserstringBrowser
osstringOperating system
devicestringDevice name (e.g., Mobile)
countrystringCountry
regionstringRegion/state/province
citystringCity
languagestringBrowser language
hostnamestringHostname
tagstringTag
eventstringEvent
distinctIdstringUnique ID
utmSourcestringUTM source
utmMediumstringUTM medium
utmCampaignstringUTM campaign name
utmContentstringUTM content
utmTermstringUTM keyword
segmentuuidUser segment UUID
cohortuuidUser group UUID

Other API parameters can be found in Umami API Documentation

References

If you enjoyed this, leave a comment~