# Embed widgets

> Embed Komashi's Service Picker and Subscription Details with the generated script, real resource IDs and optional redirect settings.

Canonical: https://komashi.com/docs/provider/Developers/widget-integration/
Language: en

Komashi widgets add a ready-made service selection or subscription interface to your website. Their content comes from your Komashi configuration, and the loader creates an iframe in the page where you place the script.

## Choose the widget

| Widget | Use it for | Required resource ID |
| --- | --- | --- |
| **Service Picker** | Display a service's plans and let a customer start a subscription flow. | `data-service-id` |
| **Subscription Details** | Display and manage a specific existing subscription. | `data-subscription-id` |

Open **Control Center → Integration → Widgets** to preview both views and copy their generated embed code. The [Widget settings](https://komashi.com/docs/provider/Settings/12widgets/index.md) guide explains the page and its empty states.

[![Service Picker example and generated embed code](https://komashi.com/docs/assets/images/integrations-service-picker.png)](/assets/images/integrations-service-picker.png)

## Embed a Service Picker

Copy the script into the HTML at the position where the widget should appear:

```html
<script
  src="https://komashi.com/widget/embed.js"
  data-komashi-widget
  data-service-id="YOUR_SERVICE_ID"
  data-view="service-picker"
></script>
```

Replace `YOUR_SERVICE_ID` with an actual service ID from the [REST API](https://komashi.com/docs/provider/Developers/api-integration/index.md) or another trusted Komashi resource. The generated example contains a placeholder; copying it without replacing the ID does not connect your service.

Use the script host generated by your own environment. Do not publish the local `komashi-app.test` address on a public website.

## Embed Subscription Details

Render the subscription ID for the customer who is entitled to see that subscription:

```html
<script
  src="https://komashi.com/widget/embed.js"
  data-komashi-widget
  data-subscription-id="YOUR_SUBSCRIPTION_ID"
  data-view="subscription-details"
></script>
```

[![Subscription Details example with an existing subscription and embed code](https://komashi.com/docs/assets/images/integrations-subscription-details.png)](/assets/images/integrations-subscription-details.png)

Use an individual subscription ID, not its group ID. The widget derives the service and provider from that subscription. A customer ID is not a substitute for the required subscription ID.

The browser receives the IDs placed in the HTML. Decide on your backend which customer and subscription the signed-in visitor is allowed to access; an arbitrary ID copied from a URL is not proof of that authorization.

## Embed attributes

| Attribute | Meaning |
| --- | --- |
| `src` | The generated `/widget/embed.js` URL. |
| `data-komashi-widget` | Marks the script for initialization by the Komashi loader. |
| `data-view` | Set `service-picker` or `subscription-details` explicitly. |
| `data-service-id` | The service ID required for Service Picker. |
| `data-subscription-id` | The subscription ID required for Subscription Details. |
| `data-customer-id` | Optional existing customer context. Only supply an appropriate customer for the integration. |
| `data-redirect-url` | Optional return destination for supported completed flows. Use an absolute URL that you control. |
| `data-is-preview` | Preview mode used by the Control Center example. Omit it for the live customer embed. |

No provider API key belongs in this script. Keep REST keys on your server.

For example, a Service Picker with a return destination adds:

```html
<script
  src="https://komashi.com/widget/embed.js"
  data-komashi-widget
  data-service-id="YOUR_SERVICE_ID"
  data-view="service-picker"
  data-redirect-url="https://your-website.example/thanks"
></script>
```

The return destination does not prove that payment succeeded. Read the subscription state when your application needs to grant access.

## Page layout and loading

The iframe fills its container's width. The loader and widget communicate its height so it can resize as the content changes. The widget language follows the provider's configured language.

Allow the widget host in any Content Security Policy that restricts external scripts or frames. Payment flows may also open a separate page; retain normal browser navigation and popup behavior.

For multiple widgets, place all their marked script elements in the HTML before the loader's first execution. The current loader initializes the script elements it discovers on that first run; there is no documented automatic rescan for embeds inserted later by a single-page application.

## Troubleshooting

| Problem | Check |
| --- | --- |
| Blank or unavailable widget | Replace placeholder IDs, verify the `data-view`, and check that the configured resource still exists. |
| Works locally but not on the public site | Use the public embed host rather than the local `.test` domain. |
| Missing iframe or script load | Check your CMS's script restrictions and your site's Content Security Policy. |
| Wrong customer or subscription | Check the backend mapping and the individual subscription ID. |
| Stale or unresponsive tab | Reload the page. Widget interaction sessions are temporary. |
| `429` response | Reduce reloads or requests and retry later. The embed and render endpoints are throttled. |

Related: [Widget settings](https://komashi.com/docs/provider/Settings/12widgets/index.md), [REST API integration](https://komashi.com/docs/provider/Developers/api-integration/index.md), [webhooks](https://komashi.com/docs/provider/Settings/11webhooks/index.md).
