Documentation [for devs]

Documentation [for devs]

 

Widget API Integration Guide

This guide explains how to authenticate, fetch data, and handle errors when working with the Widget API.

1. Get Widget Metrics

The Widget API allows you to retrieve real-time metrics for your deployed widgets.

Use the /metrics endpoint to query usage data across platforms.

1.1 Authentication

All API requests require an authentication token.

Include your token in the Authorization header as a Bearer token.

1.2 Request Example

curl -H "Authorization: Bearer $TOKEN" \
     -H "Content-Type: application/json" \
     -X GET "https://api.example.com/v1/metrics" \
     -d '{"date_range": "last_7_days", "widget_id": "abc123"}'
import requests

url = "https://api.example.com/v1/metrics"
headers = {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json"
}
payload = {
    "date_range": "last_7_days",
    "widget_id": "abc123"
}

response = requests.get(url, headers=headers, params=payload)
if response.ok:
    print(response.json())
else:
    print("Error:", response.status_code)

const headers = {
  "Authorization": "Bearer YOUR_TOKEN",
  "Content-Type": "application/json"
};

const params = new URLSearchParams({
  date_range: "last_7_days",
  widget_id: "abc123"
});

fetch(`https://api.example.com/v1/metrics?${params.toString()}`, {
  method: "GET",
  headers
})
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error("API Error", err));

1.3 Response Data

Response includes a Gaussian-distributed load pattern over time:

[Deprecated] Latex | Mosaic

Use this model to predict traffic spikes and optimise resource allocation.

1.4 Error Handling

Common HTTP errors you might encounter:

Advanced Expand | Mosaic
Advanced Expand | Mosaic

If you need help, contact