Using the statpx REST API to Pull Your Analytics Data

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:

Authorization: Bearer YOUR_API_KEY

A full curl example looks like this:

curl -H "Authorization: Bearer YOUR_API_KEY" \ "https://statpx.com/api/v1/sites"

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:

https://statpx.com/api/v1/sites?api_key=YOUR_API_KEY

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:

{ "sites": [ { "id": 12, "domain": "example.com", "created_at": "2026-01-15T09:22:00Z" }, { "id": 17, "domain": "blog.example.com", "created_at": "2026-03-02T14:05:00Z" } ] }

GET /api/v1/stats

Returns an aggregate metric value for a site over a date range. Parameters:

Example request:

GET https://statpx.com/api/v1/stats?site_id=12&metric=pageviews&range=30

Example response:

{ "site_id": 12, "metric": "pageviews", "range_days": 30, "value": 18420 }

GET /api/v1/pageviews

Returns a daily timeseries of pageview counts for a site. Useful for charting traffic trends over time. Parameters:

Example request:

GET https://statpx.com/api/v1/pageviews?site_id=12&range=7

Example response:

{ "site_id": 12, "range_days": 7, "data": [ { "date": "2026-05-18", "pageviews": 612 }, { "date": "2026-05-19", "pageviews": 588 }, { "date": "2026-05-20", "pageviews": 701 }, { "date": "2026-05-21", "pageviews": 934 }, { "date": "2026-05-22", "pageviews": 1204 }, { "date": "2026-05-23", "pageviews": 1087 }, { "date": "2026-05-24", "pageviews": 540 } ] }

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:

import requests API_KEY = "your_api_key_here" SITE_ID = 12 BASE_URL = "https://statpx.com/api/v1" headers = {"Authorization": f"Bearer {API_KEY}"} resp = requests.get( f"{BASE_URL}/pageviews", headers=headers, params={"site_id": SITE_ID, "range": 7} ) data = resp.json() total = sum(row["pageviews"] for row in data["data"]) print(f"Pageviews last 7 days: {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.

Continue reading

Features
How to Create White-Label Analytics Reports for Clients
Features
How to Track Lead Generation Funnels from Form Fill to Customer
Features
User Journey Analytics: Map the Full Path from Visit to Conversion
Analytics by statpx