> For the complete documentation index, see [llms.txt](https://docs.appmixer.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appmixer.com/getting-started/embed-your-automation-hub.md).

# Embed Your Automation Hub

The Automation Hub embeddable widget combines these features for your end-users:

* Browse and start Automations pre-built by your team
* Customize pre-built Automations
* Manage Logs and Accounts for their Automations

As you customize the Hub options such as layout, design and automation categories (tabs), the embed code shown in the Settings page will dynamically change.

You can copy the code from the Settings page or use this example code:

```javascript
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Appmixer Automation Hub – Minimal Demo</title>
</head>
<body>
  <div id="widget"></div>

  <script src="[TENANT_STUDIO_URL]/appmixer/package/appmixer.js"></script>

  <script type="module">
    const API_BASE_URL = '[TENANT_API_URL]';
    const USERNAME = 'YOUR_USERNAME';
    const PASSWORD = 'YOUR_PASSWORD';

    const appmixer = new Appmixer({ baseUrl: API_BASE_URL });
    const { token } = await appmixer.api.authenticateUser(USERNAME, PASSWORD);
    appmixer.set('accessToken', token);

    const hubEl = document.getElementById('automation-hub');
    const designerEl = document.getElementById('designer');

    // ------------------------------------------------------------------
    // Automation Hub
    // ------------------------------------------------------------------
    const automationHub = appmixer.ui.AutomationHub({
      el: hubEl,
      state: {
        flows: {
          layout: 'grid'
        }
      },
      options: {
        customization: {
          entryPoints: {
            templates: true, // "Customize" on a template card
            scratch: true    // "Create my own" button
          }
        },
        header: {
          visible: true,
          tabs: {
            hidden: []
          },
          subheader: {
            visible: false
          }
        },
        flows: {
          header: {
            layout: {
              visible: true
            }
          },
          templates: {
            header: {
              categories: {
                visible: false,
                tabs: []
              }
            }
          }
        }
      },
      l10n: {
        ui: {
          automationHub: {}
        }
      },
      theme: {
        mode: 'dark',
        variables: {
          colors: {
            surface: '#2A2A2A',
            neutral: '#FFFFFF',
            primary: '#2B75EF',
            onPrimary: '#FFFFFF',
            secondary: '#94A6D4',
            onSecondary: '#FFFFFF',
            tertiary: '#D494D0',
            onTetriary: '#FFFFFF',
            error: '#EF4444',
            warning: '#F6C20C',
            onWarning: '#FFFFFF',
            success: '#01C58D',
            onSuccess: '#FFFFFF',
            modifier: '#C558CF',
            onModifier: '#FFFFFF',
            highlighter: '#FFA500',
            separator: '#4C4C4C',
            charcoalTeal: '#2C3130',
            darkJade: '#2C4B42'
          },
          font: {
            family: '\'SF Pro Text\', \'Helvetica Neue\', \'Helvetica\', \'Arial\', sans-serif',
            familyMono: '\'SF Mono\', \'ui-monospace\', Menlo, monospace',
            weightRegular: 400,
            weightMedium: 500,
            weightSemibold: 600,
            weightBold: 700,
            size: 14
          },
          shadows: {
            level0: 'none',
            level1: 'none',
            level2: 'none',
            level3: 'none',
            level4: 'none',
            level5: 'none',
            backdrop: 'rgba(0 0 0 / 92%)',
            popover: '1px 3px 9px rgba(0 0 0 / 32%)',
            icon: 'none',
            blur: 'rgba(0 0 0 / 75%)',
            bar: 'none'
          }
        }
      }
    });

    /**
     * Show the Hub on a tab: 'flows', 'logs' or 'accounts'.
     * open() mounts the widget again, so it loads fresh data.
     */
    function showHub(tab = 'flows', logsFlowId = null) {
      automationHub.state('tab', tab);
      automationHub.set('logsFlowId', tab === 'logs' ? logsFlowId : null);
      automationHub.open();
    }

    // A template or instance card was clicked: open the Wizard.
    automationHub.on('flow:open-wizard', event => {
      const flowId = event?.data?.flow?.flowId;
      if (flowId) openWizard(flowId);
    });

    // A custom automation, "Customize" or "Create my own" was clicked: open the Designer.
    automationHub.on('flow:open-designer', event => {
      const flowId = event?.data?.flow?.flowId;
      if (flowId) openDesigner(flowId, event.data.isNew === true);
    });

    // ------------------------------------------------------------------
    // Wizard
    // ------------------------------------------------------------------
    let wizard = null;

    function openWizard(flowId) {
      if (!wizard) {
        wizard = appmixer.ui.Wizard({ flowId });

        // Every way out of the Wizard ends with 'close'.
        wizard.on('close', event => {
          event.next();           // built-in handler: close the Wizard
          automationHub.reload(); // show the new or changed instance
        });
      } else {
        wizard.set('flowId', flowId);
      }
      wizard.open();
    }

    // ------------------------------------------------------------------
    // Designer
    // ------------------------------------------------------------------
    let designer = null;
    let designerFlowId = null;
    let designerIsNew = false;
    let designerHasChanges = false;

    function createDesigner() {
      designer = appmixer.ui.Designer({
        el: designerEl,
        flowId: designerFlowId,
        options: {
          showButtonClose: true,
          showButtonConnectors: false,
          autoOpenLogs: true,
          menu: [
            { event: 'flow:rename', label: 'Rename', icon: 'am-menu-rename' },
            { event: 'flow:change-description', label: 'Change Description', icon: 'am-menu-description' },
            { event: 'flow:change-image', label: 'Change Image', icon: 'am-menu-image' },
            { event: 'flow:insights', label: 'Insights', icon: 'am-menu-insights' },
            { event: 'flow:export-svg', label: 'Export to SVG', icon: 'am-menu-export' },
            { event: 'flow:export-png', label: 'Export to PNG', icon: 'am-menu-export' },
            { event: 'flow:print', label: 'Print', icon: 'am-menu-print' },
            { event: 'flow:clone', label: 'Clone', icon: 'am-menu-clone' },
            { event: 'flow:remove', label: 'Delete', icon: 'am-menu-delete' }
          ],
          triggerSelector: {
            enabled: true,
            featured: [
              { name: 'appmixer.utils.http.WebhookTrigger', alternatives: [{ name: 'appmixer.utils.http.Webhook' }] },
              { name: 'appmixer.utils.timers.SchedulerTrigger', alternatives: [{ name: 'appmixer.utils.timers.Scheduler' }] },
              { name: 'appmixer.utils.appevents.OnAppEvent', alternatives: [{ name: 'appmixer.utils.timers.Timer' }] },
              { name: 'appmixer.utils.controls.OnStart' }
            ]
          },
          stepSelector: {
            featured: [
              { name: 'appmixer.utils.controls.Each' },
              { name: 'appmixer.utils.controls.Condition' },
              { name: 'appmixer.utils.http.Post' },
              { name: 'appmixer.utils.timers.Wait' }
            ]
          },
          toolbar: [
            ['undo', 'redo'],
            ['zoom-to-fit', 'zoom-in', 'zoom-out'],
            ['align', 'commands'],
            ['logs']
          ]
        },
        api: {
          // Track edits, so that a new flow the user never changed can be deleted on close.
          // Always pass on all arguments.
          updateFlow(flowId, changes, ...rest) {
            if (flowId === designerFlowId && ['name', 'description', 'flow'].some(key => key in changes)) {
              designerHasChanges = true;
            }
            return appmixer.api.updateFlow(flowId, changes, ...rest);
          }
        }
      });

      // Close button: go back to the Hub. Delete a new flow the user never changed.
      designer.on('close', async () => {
        if (designerIsNew && !designerHasChanges) {
          try {
            await appmixer.api.deleteFlow(designerFlowId);
          } catch (err) {
            console.error(err);
          }
        }
        designer.close();
        showHub('flows');
      });

      // Menu > Insights: show the Hub's Logs tab for this flow.
      designer.on('flow:insights', event => {
        designer.close();
        showHub('logs', event?.data?.flowId ?? designerFlowId);
      });

      // Menu > Clone: clone the flow and open the clone.
      designer.on('flow:clone', async event => {
        try {
          designer.state('loader', true);
          const cloneId = await appmixer.api.cloneFlow(event?.data?.flowId ?? designerFlowId, {
            connectAccounts: true,
            prefix: 'Clone of '
          });
          designer.close();
          openDesigner(cloneId, false);
        } catch (err) {
          designer.state('error', `Failed to clone the flow: ${err.message}`);
        } finally {
          designer.state('loader', false);
        }
      });

      // After Menu > Delete: go back to the Hub.
      designer.on('flow:remove-after', () => {
        designer.close();
        showHub('flows');
      });
    }

    function openDesigner(flowId, isNew) {
      automationHub.close();

      designerFlowId = flowId;
      designerIsNew = isNew;
      designerHasChanges = false;

      if (!designer) {
        createDesigner();
      } else {
        designer.set('componentId', null);
        designer.set('flowId', flowId);
      }
      designer.open();
    }

    // ------------------------------------------------------------------
    // Start
    // ------------------------------------------------------------------
    showHub('flows');
  </script>
</body>
</html>
```

### Authenticating your end users

[Read more about authenticating your users](/getting-started/embed.md#authenticate-your-end-users) in the dedicated documentation section.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.appmixer.com/getting-started/embed-your-automation-hub.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
