Skip to main content

Secure Embedding with JavaScript

The recommended way to embed a dashboard is to fetch a secure token from your backend and dynamically create the iframe. This keeps your API credentials safe.
Although this guide demonstrates iframe embedding, the same backend pattern of generating a signed token server-side also applies when embedding Papermap through @papermap/papermap. If you are embedding PaperChat, PaperCard, or PaperBoard, see React Components.
Security Best Practice: Never expose your API credentials (API Key ID and Secret Key) in your frontend code. Always generate tokens on your backend server and fetch them from your frontend.
To generate tokens on your backend, see the Backend: Generating Embed Tokens section below for implementation examples in Python, TypeScript, PHP, and Go.
To get the dashboardId for your dashboard, navigate to your Papermap workspace and click the top-left dropdown menu to view all dashboards. Select the “Show All Dashboards” section to view information about all dashboards including the dashboardId
The same dashboardId can also be used by the React components package when rendering PaperChat, PaperCard, and PaperBoard.

React Example

Why This Approach is Secure: - Your API credentials stay on the server, never exposed to the browser - Tokens are time-limited. Each user gets a fresh token when they load the page - You can add authentication checks before generating tokens

Frontend Token Generation (Testing Only)

For Development/Testing Only: This approach exposes your API credentials in the frontend code. Only use this for local development or testing. Never use this in production applications.
For quick testing or prototyping, you can generate tokens directly in the frontend:
When to Use Frontend Generation: - ✅ Local development and testing - ✅ Internal tools with restricted access - ✅ Quick prototypes and demos - ❌ Never in production (credentials exposed to users) - ❌ Public-facing applications - ❌ Applications requiring authentication

Simple iframe Embedding

For testing purposes, you can also use a static iframe with a pre-generated token:

Complete Example

Here’s a full HTML example using kebab-case naming:

Responsive Design

CSS Styling

Make your embedded dashboards responsive:

Backend: Generating Embed Tokens

To securely embed dashboards, you need to generate a signed token from your backend. Here’s how to create the token:

Token Generation

Usage Example

Security Note: Always store your API credentials in environment variables, never hardcode them in your source code. The token is valid for how long you set it for but it is recommended to be 1 hour for security sake.

Next Steps

Configuration

Learn about advanced configuration options and customization parameters for your embedded dashboards

Parameter Usecases

Explore common parameter combinations and use cases for different embedding scenarios

Troubleshooting

Common issues and solutions for embedding Papermap dashboards in your application