Using the statpx REST API to Pull Your Analytics Data
The statpx dashboard gives you a clear visual summary of your site's traffic. But a dashboard is only one way to consume analytics data. For developers, data teams, and automation-minded site owners, a REST API opens up a different set of possibilities: feeding traffic numbers into your own tools, building custom reports, triggering workflows based on real data, and integrating analytics into places the standard UI was never designed to reach.
The statpx API is designed to be straightforward. Authenticate with a Bearer token, call an endpoint, receive JSON. This guide covers why you would use it, how authentication works, which endpoints are available, and what the responses look like.
Why Use an Analytics API
The most common reason to reach for an API rather than a dashboard is that you need the data to live somewhere other than a web browser. Some practical examples:
Custom Dashboards
Your team might already have a dashboard in Grafana, Notion, a custom internal tool, or a Retool app. Rather than maintaining a separate browser tab for analytics, you can pull statpx data into the same view your team already uses. A single unified dashboard reduces context-switching and makes cross-metric correlation easier — you can put traffic trends next to revenue numbers, support ticket volume, or deployment history.
Slack or Chat Bots
A bot that posts a daily traffic summary to your team's Slack channel, or alerts a channel when pageviews exceed a certain number, is easy to build with an API and a basic script. The bot runs on a schedule, calls the API, formats the result, and posts it. No manual checking, no report to pull — the data comes to the team automatically.
Spreadsheet Automation
Google Sheets and Excel both support pulling data from external APIs via scripts. A Google Apps Script that runs daily, calls the statpx API, and appends today's pageview count to a sheet gives you a growing historical record that you can chart, share, and analyze without ever opening the analytics dashboard.
CI/CD Pipeline Checks
After deploying a new version of your site, a post-deploy check can query the pageviews timeseries endpoint and compare traffic in the minutes after deploy to the same window the day before. A significant drop immediately after a deploy is a strong signal that something broke. Catching this in the pipeline, before the next morning's standup, is materially better than finding out hours later.
Third-Party Integrations
If you use tools that can call webhooks or external APIs — Zapier, Make, n8n — the statpx API is connectable. Pull weekly pageview counts into a CRM note, log daily session totals to a project management tool, or trigger a Slack notification when sessions drop below a threshold that your own alerting does not cover.
Authentication
All API requests require authentication. statpx uses API keys, which you generate from the API Keys page in your account settings. Each key has a name you choose, so you can create separate keys for different integrations and identify which one is in use if you need to revoke it.
Important: the full API key is shown only once, immediately after generation. Copy it and store it securely — a password manager is the right place. If you lose the key, you must generate a new one; there is no way to retrieve the original value.
Using Bearer Token Authentication
Pass your API key in the Authorization header of every request:
A full curl example looks like this:
Using the Query Parameter
Alternatively, you can pass the key as a query parameter. This is useful for quick testing in a browser or in tools that do not support custom headers easily:
The header method is preferred for production use. Query parameters can appear in server logs and browser history, which makes them less suitable for long-lived keys.
Available Endpoints
The statpx API currently exposes three endpoint groups.
GET /api/v1/sites
Returns a list of all sites associated with your account. Use this to discover your site IDs, which are required parameters for the other endpoints.
Example response:
GET /api/v1/stats
Returns an aggregate metric value for a site over a date range. Parameters:
site_id— required, the numeric ID from /api/v1/sitesmetric— required; one ofpageviews,sessions,unique_visitors,bounce_raterange— number of days to look back (e.g.,30for the last 30 days)
Example request:
Example response:
GET /api/v1/pageviews
Returns a daily timeseries of pageview counts for a site. Useful for charting traffic trends over time. Parameters:
site_id— requiredrange— number of days (e.g.,7for the past week)
Example request:
Example response:
Get your API key now
statpx API keys are free with every account. Generate a named key, copy it once, and start querying your analytics data from any language or tool. Revoke it anytime from the API Keys page.
Try statpx free →Managing API Keys
The statpx API Keys page (found in your account settings) is where you create, name, and revoke keys. A few practical guidelines:
Use One Key per Integration
Create a separate named key for each use case: one for your Slack bot, one for your Google Sheet, one for your CI pipeline. If you ever need to revoke access for one of them — because a project ends, a team member leaves, or a key is exposed — you can revoke just that key without disrupting the others.
Name Keys Descriptively
A key named "slack-weekly-digest" or "grafana-dashboard-prod" is easier to manage than "key1" or "api-key-june". The name is the only metadata you have after the key value is gone.
Rotate Keys Periodically
For long-lived integrations, rotating your API key every few months is a reasonable security habit. Generate the new key, update the integration, verify it works, then revoke the old key. The transition takes a few minutes and reduces the window of exposure if an old key was ever captured in a log somewhere.
A Simple Python Example
To illustrate how straightforward the API is to use, here is a minimal Python script that fetches the last 7 days of pageviews for a site and prints the total:
The same pattern works in Node.js, Ruby, PHP, Go, or any language with HTTP support. The API follows standard REST conventions — GET requests, query parameters, JSON responses, HTTP status codes for errors — so it integrates cleanly with any toolchain.
What to Build Next
The API is a starting point, not an endpoint. Once you have your data flowing into a custom integration, the useful things you can do with it compound. A Slack bot that started as a daily pageview summary can grow to include top pages, traffic source breakdowns, and week-over-week comparisons. A CI check that started as a basic drop detector can evolve into a full traffic health gate that blocks deploys when anomalies are detected.
The constraint is not the data — it is your imagination about what to do with it. Start with one simple integration, get it working, and let it grow from there.
The Bottom Line
An analytics REST API turns your traffic data from a dashboard-only view into a programmable resource — one you can feed into Slack bots, spreadsheets, CI pipelines, or any internal tool your team already uses. The practical step is to start small: generate a named API key, write a five-line script that pulls last week's pageviews, and get that working before building anything more ambitious. Once the data is flowing, useful integrations compound quickly. statpx exposes pageviews, sessions, unique visitors, and bounce rate through its API, with daily timeseries available for charting traffic trends in whatever tool you prefer.