The embed feature requires an ApiTraffic API token on your server to generate signed embed tokens. The client-side SDK never sees your API token.
How It Works
- Your backend calls the ApiTraffic API with your API token to generate a signed embed JWT.
- The JWT locks in the bucket, filters, and theme — the client SDK cannot tamper with these.
- Your frontend passes the JWT to the
<apitraffic-request-log>Web Component. - The component fetches data directly from ApiTraffic’s embed endpoints using the JWT.
Generate an Embed Token (Server-Side)
Token Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
bucketSid | string | Yes | — | The bucket to scope the embed to. |
view | string | No | 'request-log' | The embed view type. |
filters | object | No | {} | Filters locked into the token (see below). |
ttl | number | No | 3600 | Token lifetime in seconds (60–86400). |
theme | string | No | 'light' | Theme preference: 'light', 'dark', or 'auto'. |
Filter Options
| Filter | Type | Description |
|---|---|---|
environmentSid | string | Filter to a specific environment. |
criteria | string | Search criteria string (same syntax as the API). |
streamViewSid | string | Use a saved stream view’s filter criteria. |
Vanilla JavaScript
Installation
Basic Usage
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
token | string | — | Required. The signed embed JWT. |
theme | string | 'light' | 'light', 'dark', or 'auto'. |
api-url | string | 'https://api.apitraffic.io/v1' | Override the API base URL (self-hosted). |
page-size | number | 25 | Requests per page (1–100). |
show-detail | string | 'true' | Set to 'false' to disable row expansion. |
Events
React
Installation
Drop-In Component
Props
| Prop | Type | Default | Description |
|---|---|---|---|
token | string | — | Required. The signed embed JWT. |
theme | string | 'light' | 'light', 'dark', or 'auto'. |
apiUrl | string | — | Override the API base URL. |
pageSize | number | 25 | Requests per page. |
showDetail | boolean | true | Enable/disable expandable row detail. |
onTokenExpired | function | — | Return a new token string to auto-refresh. |
onReady | function | — | Fires after the first successful load. |
onError | function | — | Fires on API errors. |
onRequestClick | function | — | Fires when a row is clicked. |
Headless Hook
UseuseApiTrafficEmbed when you want full control over rendering:
Theming
The Web Component uses CSS custom properties for theming. Override them on the host element:Available CSS Custom Properties
| Property | Default | Description |
|---|---|---|
--at-font-family | System font stack | Font family |
--at-font-size | 13px | Base font size |
--at-bg-color | #ffffff | Container background |
--at-text-color | #1f2937 | Primary text color |
--at-text-muted | #6b7280 | Secondary/muted text |
--at-accent-color | #3b82f6 | Links, buttons, GET method |
--at-danger-color | #ef4444 | Errors, DELETE method |
--at-border-color | #e5e7eb | Border color |
--at-border-radius | 6px | Container border radius |
--at-row-hover-bg | #f9fafb | Row hover background |
--at-max-height | none | Max height (set for scrolling) |
Dark Mode
Settheme="dark" for a built-in dark theme, or theme="auto" to follow the user’s OS preference via prefers-color-scheme.
Token Refresh Flow
Embed tokens are short-lived by design. The SDK fires atoken-expired event approximately 30 seconds before expiry, giving your app time to fetch a fresh token seamlessly:
Security
How are filters protected?
How are filters protected?
All filters (bucket, environment, criteria, stream view) are cryptographically signed into the JWT using HMAC-SHA256. The client SDK reads the token to display data but cannot modify the filters. Any tampering invalidates the signature.
Can the client access data outside the filter scope?
Can the client access data outside the filter scope?
No. The embed data endpoints extract the
accountSid, bucketSid, and all filters directly from the verified JWT payload. Query parameters from the client are ignored for filtering — only pagination cursors (from, limit) are accepted.What happens if a token is stolen?
What happens if a token is stolen?
Tokens are short-lived (default 1 hour, max 24 hours) and scoped to a specific bucket and filter set. An attacker can only see the same data the embed was designed to show, and only until the token expires. You can also rotate the signing secret by calling the token endpoint — a new secret is auto-generated if the existing one is cleared.
Is my API token exposed to the browser?
Is my API token exposed to the browser?
No. Your API token is only used server-side to generate embed JWTs. The browser only ever sees the embed JWT, which cannot be used to access any other ApiTraffic API endpoints.
API Reference
Create Embed Token
Get Embed Requests
Get Embed Request Detail
Troubleshooting
Component shows 'No requests found'
Component shows 'No requests found'
Verify the
bucketSid in your token request matches a bucket that has traffic. Check that any filters aren’t too restrictive.401 errors in the browser console
401 errors in the browser console
The embed token has likely expired. Implement the
apitraffic:token-expired event handler (or onTokenExpired prop in React) to auto-refresh.Styles look wrong or are overridden
Styles look wrong or are overridden
The component uses Shadow DOM, so your page styles should not affect it. If you see issues, ensure you’re setting CSS custom properties on the
apitraffic-request-log element itself, not inside its shadow root.Component doesn't render
Component doesn't render
Ensure the SDK script or import is loaded before the element appears in the DOM. With the CDN approach, place the
<script> tag before the component. With bundlers, ensure import '@apitraffic/embed' is called.