> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketflows.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Render an embed in your application

> Create an embed for a business on your server and display it in an iframe

`Embeds` provide a complete user experience for editing campaigns, email templates, and other
marketing primitives available within Pocketflows. For when to use them, see
[Businesses, customers, and embeds](https://docs.pocketflows.com/concepts/data-model.md#embeds).

The work is split between your server, which creates the embed, and your frontend, which displays it.
Before you start, read [How embeds are secured](https://docs.pocketflows.com/concepts/embeds.md): the embed's URL works without a
login, so who receives it matters.

## 1. On your server: create the embed

Add an endpoint to your application that your frontend calls when a business owner opens your
marketing page. In it:

1. Check the user's session, and look up which business they belong to from your own records. Don't
   accept a business ID from the browser.

2. Find that business's Pocketflows ID, which you saved when you
   [synced the business](https://docs.pocketflows.com/how-to/sync-businesses-and-customers.md).

3. Create an embed for it, using your secret key:

   ```
   POST /businesses/:business_id/embeds
   ```

   ```json theme={null}
   {
     "id": "e_XXXXXX",
     "business": "bu_XXXXX",
     "expires_at": "2026-03-31T16:42:03.155123Z",
     "url": "https://api.pocketflows.com/embeds/e_XXXXXX/show"
   }
   ```

4. Return the `url` to your frontend, and nothing else from the response.

Create a new embed each time the page opens, rather than storing a URL and reusing it.

## 2. In your frontend: display it

Pass the `url` as the `src` of an `iframe`:

```html theme={null}
<iframe src="{url}"></iframe>
```

We recommend that the `iframe` take up as much of the viewport as possible.

## 3. Handle expiry

An embed expires 7 days after it's created. If a business owner keeps the page open past `expires_at`,
the embed tells them their session has expired. Reloading your page fetches a new URL from step 1, so
no extra handling is needed if your page always creates a new embed when it loads.

## Related

* [How embeds are secured](https://docs.pocketflows.com/concepts/embeds.md) for what an embed URL grants and how long it lasts.
* [Set up custom domains](https://docs.pocketflows.com/how-to/set-up-custom-domains.md): custom domain setup is built into the embed
  UI.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.