The ability to retrieve metrics is at the heart of Calibre’s API. In this guide we'll demonstrate how to fetch metrics for your pages efficiently.
Timeseries metrics for a given Site#
You can query up to 6 months of reporting data per request. Use from and to parameters to specify date ranges.
Read Sites
calibre site metrics --site=calibre --json --metrics=largestContentfulPaint --metrics=lighthousePerformanceScore#!/usr/bin/env node
import { TimeSeries } from 'calibre'
const getTimeseries = async ({ site, from, to, pages, profiles, measurements }) => {
const results = await TimeSeries.list({
site,
from,
to,
pages,
profiles,
measurements
})
// Output the formatted JSON response
console.log(JSON.stringify(results, null, 2))
}
const siteSlug = 'calibre'
const to = new Date()
// 7 days of history
const from = new Date()
from.setDate(to.getDate() - 7)
// Filter by page and/or test profile (omitting `page` will return all pages, omitting `profile` will return all profiles)
const pages = ['a48ddb67-0da5-4731-91c4-42239009b463']
const profiles = ['ddbf3952-4b96-4657-88a1-60abb097f44e']
// Filter the metrics to be returned (omitting `measurements` will return all available measurements)
const measurements = ['lighthousePerformanceScore', 'totalBlockingTime']
getTimeseries({ site: siteSlug, from, to, pages, profiles, measurements })| Parameter | CLI | Node.js API | Description |
|---|---|---|---|
| site | --site | site | The site slug |
| from | --from | from | Start date for the query (ISO 8601 format) |
| to | --to | to | End date for the query (ISO 8601 format) |
| pages | --page | pages | Filter by page UUID(s) |
| profiles | --profile | profiles | Filter by test profile UUID(s) |
| measurements | --metrics | measurements | Filter by metric name(s) |
Metrics from a single Snapshot#
Read Sites
calibre site get-snapshot-metrics --site=calibre --snapshot=2000 --json#!/usr/bin/env node
import { SnapshotMetrics } from 'calibre'
const getSnapshotMetrics = async ({ site, snapshotId }) => {
const results = await SnapshotMetrics.snapshot({ site, snapshotId })
// Output the formatted JSON response
console.log(JSON.stringify(results, null, 2))
}
const siteSlug = 'calibre'
const snapshotId = 1000
getSnapshotMetrics({ site: siteSlug, snapshotId })curl -X GET -H "Accept: application/json" \
https://calibreapp.com/api/sites/<site>/snapshots/<snapshotId>?secret=<secret>| Parameter | CLI | Node.js API | Description |
|---|---|---|---|
| site | --site | site | The site slug |
| snapshot | --snapshot | snapshotId | The snapshot ID |