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

# Workflows

> Let your customers build paths of compositions in your page, and show them with one embed tag

A workflow chains compositions together, with filters between them that decide which composition a visitor sees next. On a page it is still the `<widgetic>` tag you already use: the embed follows the workflow, so the composition on screen is replaced by the next one, in the same place.

You can put the screen where workflows are built (see it in [the gallery](https://docs.widgetic.com/docs/partners/ui-components#the-pieces)) in your own page, for **one customer at a time**. Your customer makes workflows from their own compositions, tries them, publishes them and pauses them, without leaving your product and without a Widgetic account. Your server keeps your API key. The page only holds an [editor session](https://docs.widgetic.com/docs/partners/editor-sessions.md). Your server can also read and change your customers' workflows itself, one customer at a time (see [From your server](#from-your-server)). And you can offer your customers somewhere to start: workflows of your own that they copy and build on, from a page of yours (see [Starting points](#starting-points)).

Like every piece, it is mounted with the [UI SDK](https://docs.widgetic.com/docs/partners/ui-components), and installing the SDK, tokens, the theme, the language and the Content Security Policy are the same for every piece, and are on [the UI Components page](https://docs.widgetic.com/docs/partners/ui-components). This page covers what is specific to Workflows.

> [!NOTE]
>
> A customer can make workflows in their own browser. A/B tests and translations have no screen in a session: your server makes them for the customer, with your key and the customer's header (see [A/B Tests and Translations](https://docs.widgetic.com/docs/partners/ab-tests-and-translations.md)).

## How it works

**1. Your server makes an editor session**

When the page that holds the screen opens, your server asks Widgetic for a session for the signed-in customer, with the `workflows` surface, and returns the token. See [Make a session](#make-a-session).

**2. Your page mounts the screen**

The [UI SDK](https://docs.widgetic.com/docs/partners/ui-components) draws it in your container, with the id of your partner workspace as its `workspaceId` and a `getToken` that fetches the token from your server. See [Mount the screen](#mount-the-screen).

**3. Your customer builds and publishes**

They chain their own compositions, play a visitor through the draft with **Test run**, and publish. Every call the screen makes carries the token, so it reaches that customer's workflows and compositions and nobody else's. See [What belongs to whom](#what-belongs-to-whom).

**4. Your page shows the embed tag**

The screen tells your page which workflow the customer asked the embed code of, and your page shows the `<widgetic>` tag that goes on the customer's own page. See [Show a workflow on a page](#show-a-workflow-on-a-page).

## Make a session

Call this from your server, as for any other piece (see [Editor Sessions](https://docs.widgetic.com/docs/partners/editor-sessions.md#make-a-session)). `{id}` is Widgetic's `id` for the managed user, not your own `externalId`.

```bash theme={"theme":"css-variables"}
curl -sS -X POST "https://api.widgetic.com/v1/managed-users/$MANAGED_USER_ID/editor-sessions" \
  -H "Authorization: Bearer $WIDGETIC_PARTNER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "surfaces": ["workflows"],
    "expiresInSeconds": 3600,
    "allowedOrigin": "https://app.example.com"
  }'
```

* **`workflows` is enough on its own.** The screen, its assistant included, calls nothing outside its own workflow calls. Add `files` only when your customers should be able to attach a file to a message of [the assistant](#the-assistant-beside-the-canvas): the screen then uploads it first, with the same session. A page that also mounts the Composition Editor or the Widget Creator asks for their surfaces in the same call, because [the surfaces do not imply one another](https://docs.widgetic.com/docs/partners/editor-sessions.md#surfaces).
* **The rest is the same as for every session.** The token is shown once, the session lasts up to four hours, `allowedOrigin` binds it to your page, and it is made only while your account is in force and your own [storage](https://docs.widgetic.com/docs/partners/storage.md) works, even though this screen stores no file of its own (an attached file goes to your storage).
* **One endpoint of yours serves every piece.** The endpoint in [A server endpoint for your page](https://docs.widgetic.com/docs/partners/editor-sessions.md#a-server-endpoint-for-your-page) makes the session with the surfaces the page needs.

## Mount the screen

Give the container a height: the screen fills it and scrolls inside it.

```javascript theme={"theme":"css-variables"}
import { mountModule } from '@widgetic/ui-sdk';

// The workspaceId that every editor session of your account answers with (the same one for all your customers).
const PARTNER_WORKSPACE_ID = '7d1f0b6e-2c44-4a37-b0a1-6f5d1e9c2a58';

const workflows = await mountModule('workflows', {
  container: document.querySelector('#workflows'),
  workspaceId: PARTNER_WORKSPACE_ID,
  getToken: async () => (await fetch('/widgetic-session', { method: 'POST' })).json(), // { token, expiresAt }
  workflowId: workflowOfTheAddress(), // optional: the workflow to open first. Leave it out for the list
  theme: 'system',
  on: {
    ready: () => console.log('Workflows is on screen'),
    openWorkflow: ({ workflowId }) => history.pushState(null, '', workflowId ? `/workflows/${workflowId}` : '/workflows'),
    showEmbedCode: ({ workflowId }) => showMyEmbedCodeDialog(workflowId),
    error: ({ message, code, fatal }) => report(code, message),
  },
});

// The page owns where the person is: when it moves (the back button), tell the screen.
window.addEventListener('popstate', () => workflows.module.setWorkflow(workflowOfTheAddress()));

// later:
await workflows.unmount();
```

* **`workspaceId` is required.** It is the id of your partner workspace, where your customers' workflows are filed, and it is the `workspaceId` that the answer of every [editor session](https://docs.widgetic.com/docs/partners/editor-sessions.md#make-a-session) carries, the same for all your customers. Keep it in your page's configuration, or have your endpoint send it with the token. An editor session can make only the workflow calls of that workspace, and the workflows it shows are its customer's own: the id of any other workspace is refused with `404` and `RESOURCE_WORKSPACE_NOT_FOUND`, and a word where the id belongs (`me`, say, which is not a workspace) with `403` and `EDITOR_SESSION_ROUTE_NOT_ALLOWED`. The screen then says that something went wrong, with a **Try again** button, and does not show an empty list in its place.
* **`getToken` gives the token of the customer's editor session,** made with the `workflows` surface (see [Make a session](#make-a-session)): the screen then reaches that customer's own workflows and compositions, and nothing else. **A session that was made without the `workflows` surface is refused** with `403` and `EDITOR_SESSION_ROUTE_NOT_ALLOWED`. `getToken` is called once before the screen appears (a `getToken` that fails fails the mount), and again when the token is about to run out or the API refuses it (`reason: 'expired'`, once per refusal), as in [Tokens](https://docs.widgetic.com/docs/partners/ui-components#tokens). The screen never stores a token, and no API key ever reaches the page. When the session ends, the screen tells your page with an `error` event (`SESSION_ENDED`).
* **Your page owns where the person is.** The screen opens `workflowId` first, and the list when you leave it out. When the person opens a workflow or goes back to the list, the screen says so with `openWorkflow` (`workflowId` is `null` for the list), so your page can keep its address in step. When your page moves, as with the back button, `workflows.module.setWorkflow(workflowId)` moves the screen (`null` for the list). The screen writes nothing to your address bar, your storage or your cookies.
* **The embed code is yours to show.** The screen has its **Embed code** button only when something listens for `showEmbedCode` at the moment it mounts, and only for a workflow that has been published. See [Show a workflow on a page](#show-a-workflow-on-a-page).
* **Look and language are as for the other pieces.** `theme`, `setTheme`, `locale`, `messages` and `setLanguage` work as described in [Make the pieces look like your product](https://docs.widgetic.com/docs/partners/ui-components#make-the-pieces-look-like-your-product) and [Show the pieces in the language of your customers](https://docs.widgetic.com/docs/partners/ui-components#show-the-pieces-in-the-language-of-your-customers), the 65 built-in languages included, and a language written right to left turns the screen around.
* **Events.** `ready`, `openWorkflow` and `showEmbedCode` (above), and `error`. `error` has `fatal: true` when the screen could not start (and `mountModule` rejects as well). With `fatal: false` the screen carries on: `RENDER_FAILED` (a part of it could not be drawn: the rest stays and the person is offered "Try again" in its place), `REQUEST_FAILED` (a request to the API failed: the screen tells the person by itself), `SESSION_ENDED` (the API no longer accepts the token `getToken` gives) and `TOKEN_REFRESH_FAILED` (a refresh of the token failed and will be tried again).
* **What it weighs.** It is downloaded when you mount it, and only then: about 0.2 MB gzipped to start, and about 0.3 MB gzipped once all the parts of the editor have been loaded. What each version of the screen changes is in [Versions & Changelog](https://docs.widgetic.com/docs/partners/module-versions.md).

## What a customer can do

With a session, the screen offers a customer what it offers anybody:

* **The list.** The customer's own workflows, with search, sort and a switch for the archived ones.
* **A new workflow.** **New workflow** makes a blank workflow at once, named *Untitled*, and opens it. The customer names it and chooses the composition of each block in the editor, from their own compositions. The screen offers no starting points of its own (see [Starting points](#starting-points)).
* **The editor.** A canvas of blocks that go forward only (up to 25), a draft that is saved while they work, and **Test run**, which plays a visitor through the draft.
* **Publish and Discard changes.** A published version never changes. The customer can read the history of versions and restore one as a new draft.
* **Settings.** The time zone, the **Embed code** button, **pause** and **resume**, **archive** and **unarchive**.
* **Duplicate and delete.** A duplicate is a new draft. A customer can delete a workflow in any state (see [Delete a workflow](#delete-a-workflow)).
* **Runs.** How many visitors went through each block.
* **The assistant.** A chat beside the canvas that reads the open workflow, tries it and changes the draft for them, with their own compositions (see [The assistant beside the canvas](#the-assistant-beside-the-canvas)).

A session reaches nothing else of the customer's account, and nothing of yours (see [What a session never does](https://docs.widgetic.com/docs/partners/editor-sessions.md#what-a-session-never-does)). It may set only the fields the screen sets: a request that names another one, such as the customer or the state of a workflow, is refused with `403` and `EDITOR_SESSION_FIELD_NOT_ALLOWED`.

### Delete a workflow

A customer can delete a workflow in **any state**: a draft, a live workflow, a paused one or an archived one. The screen asks them to confirm and says what goes: the draft, the published versions and the counts, with how many visitors the workflow had so far. **It cannot be undone**: archiving is what keeps a workflow. The compositions it chained are not touched.

A page whose embed still names the deleted workflow does not break. It shows the embed's first composition, as it does for a paused workflow. Your webhook is told (`workflow.deleted`, see [What you are told](#what-you-are-told)).

Your server deletes with `DELETE /workspaces/{workspaceId}/workflows/{workflowId}` and the customer's header (see [From your server](#from-your-server)). A workflow that is already gone answers `404` with `RESOURCE_WORKFLOW_NOT_FOUND`.

## The assistant beside the canvas

The screen has a chat beside the canvas, the **Workflow assistant**. With a session your customer has it too, and it works for that customer alone: it is the chat a person signed in on widgetic.com uses, in a smaller edition.

Your customer can ask it, in their own words, to:

* **Read the workflow that is open** and say what it does.
* **Change the draft**: add or remove blocks, rename the workflow and change how the blocks lead to one another. The screen shows the new draft while the assistant is still answering. It only ever changes the **draft**, so the live version does not move until the customer publishes.
* **Try it.** It plays a visitor through the draft, as **Test run** does, without publishing anything.
* **Use their own compositions** as the blocks of the path, by name.

When it needs an answer it asks first, with a question the customer clicks.

It stays inside the workflow that is open and inside what that customer made:

* **Their own compositions only.** The compositions it can offer, and the ones the customer mentions in a message, are the ones filed under that customer. Another customer's composition, one you made for yourself and one that does not exist all read as missing, and a message that names a workflow or a composition that is not theirs is refused with `404`, the same one that answers for something that does not exist.
* **Never a publish, a pause or a delete.** Those are the buttons of the screen, and the customer presses them.
* **No widgets, no templates, no plans.** It does not build widgets, copy templates or make a plan, so it changes nothing outside the open workflow.
* **No suggestions in the box.** The box does not offer what to write next for a customer.
* **A file is an extra.** A customer can attach a file to a message when the session also has the `files` surface (see [Make a session](#make-a-session)). The file is theirs, in your storage, and the assistant does not put a file into a composition.

It uses **no credits**, yours or the customer's, and is counted for each customer on its own (see [Limits and cost](#limits-and-cost)). A partner's key does not call it: it is the panel of the screen, and your server has nothing to ask it.

## What belongs to whom

* **A workflow is filed under the customer when it is made.** A workflow made in a session is filed under the session's managed user, at that moment. The session cannot change that, as it has no field to name another customer. You can move it to another customer, or take the label off, from your server with your own key: see [Moving Content to Another Managed User](https://docs.widgetic.com/docs/partners/managed-users.md#moving-content-to-another-managed-user).
* **A customer sees their own workflows only.** Another customer's workflow, one of yours and one that does not exist all answer `404` with the code `RESOURCE_WORKFLOW_NOT_FOUND` and the same words, so the customer cannot tell them apart. A workflow id that is not an id is not a route at all: it answers `403` and `EDITOR_SESSION_ROUTE_NOT_ALLOWED`.
* **A customer chains their own compositions only.** The compositions the screen offers are the ones filed under that customer (see [Content the editors can open](https://docs.widgetic.com/docs/partners/editor-sessions.md#content-the-editors-can-open)). Another customer's composition, one you made without naming a customer and one of another account all read as missing: starting a workflow from one answers `404` with `RESOURCE_COMPOSITION_NOT_FOUND`, and a draft that holds one as a block cannot be published (`422` with `BUSINESS_OPERATION_INVALID`, and the block is named).
* **Your account owns the workflows.** They run under your account and your agreement, as your compositions do. While your account is paused or stopped by an unpaid invoice, a workflow is not served either (see [Account Status](https://docs.widgetic.com/docs/partners/account-status.md)). When your partnership ends, workflows are still served during the 60-day wind-down, and not once it is closed (see [Ending a Partnership](https://docs.widgetic.com/docs/partners/ending-a-partnership.md)). A customer is never asked to upgrade a plan, and is never shown yours: workflows are part of the partner contract.
* **You see all of them.** Signed in as your own account, the same screen lists every customer's workflows next to yours, and you can open, pause or delete any of them. Your key without a customer header does the same: the list holds every customer's workflows, each with the id of its customer in `managedUserId`. A workflow or a copy you make that way is yours, not the customer's.
* **Deleting a managed user does not delete their workflows.** The workflows stay in your account and keep working on every page that shows them, and only the label that said whose they were is removed. Pause or delete a customer's workflows first when they should stop. See [Deleting Managed Users](https://docs.widgetic.com/docs/partners/managed-users.md#deleting-managed-users).

## Limits and cost

* **Workflows take no credits.** Making, saving and publishing one is not an AI call, so it does not use your credits and it is not counted against a customer's allowance. Neither does starting one from a starting point: that copies what already exists and generates nothing.
* **The assistant uses no credits and has a limit of its own.** A customer can send up to 30 messages a minute, counted for each customer, so one busy customer does not slow another down. A message over the limit is refused with `429` and `RATE_LIMIT_USER_EXCEEDED`, and the screen tells the customer to wait.
* **A workflow has up to 25 blocks.**
* **You can offer up to 50 starting points, and each chains at most 10 different widgets.** See [What can be offered](#what-can-be-offered).

## Starting points

A starting point is a workflow of yours that your customers can copy and build on, so that they do not begin with an empty canvas: a welcome page that leads to an offer, a quiz with a result page for each answer. You build and publish it once, in your own account, offer it under a key, and your customers start from it.

The screen itself always starts a new workflow blank, as the Widget Creator always opens on a blank canvas: it never lists your starting points. Offering them is for your page. List them on a page of your own, as Widgetic does with its templates, and when a customer picks one, start the copy from your server and open it in the screen with `workflowId` (see [Start one](#start-one)).

> [!NOTE]
>
> Your dashboard calls them **presets**. They are not the [preset widgets](https://docs.widgetic.com/docs/partners/managed-users.md#preset-widgets), which are single widgets that your server hands out. A starting point can chain only widgets that you offer that way (see [What can be offered](#what-can-be-offered)).

### What a customer gets

A customer who starts from one of yours gets, in their own account:

* **Their own copy of every widget** the workflow chains: an ordinary private widget, filed under the customer, that serves the published code of yours.
* **A composition of their own on each copy**: a draft, with the content, design, embed settings and tables of the original.
* **A draft workflow**, wired like the live version of yours at that moment. It is named as the customer asks, or after the starting point.

The workflow stays a draft: the customer tries it, changes it and publishes it themselves. **Nothing is shared afterwards.** What a customer changes never reaches your workflow, and what you change later never reaches their copy. Publishing a new version of yours changes what the customers who start after that get, and never what the customers who already started have.

A customer sees only the starting points of **your** account. Widgetic's own are never shown to your customers, and another partner's customers never see yours.

### What can be offered

A starting point is one of **your own published workflows**: one made in your own account (not filed under a customer, and not a team's), that is not archived and has a live version. Because a customer gets copies, it also has to be something you are willing to give away:

* **Every composition in it is one you made for yourself.** A composition made for a customer or for a team is not yours to give.
* **It chains at most 10 different widgets**, because every start copies them.
* **Every one of those widgets is already one of your [preset widgets](https://docs.widgetic.com/docs/partners/managed-users.md#preset-widgets).** Offering a widget as a preset is how you say that it may be copied.

You can offer up to 50 workflows. A workflow is offered once, under one key.

### Offer one

Offer a workflow in your [dashboard](https://docs.widgetic.com/docs/partners/dashboard.md) (**Presets**, then **Workflow starting points**, then **Add a starting point**), or from your server with `PUT /partners/{partnerId}/workflow-presets/{key}`:

```bash theme={"theme":"css-variables"}
curl -sS -X PUT "https://api.widgetic.com/v1/partners/$WIDGETIC_PARTNER_ID/workflow-presets/welcome-then-offer" \
  -H "Authorization: Bearer $WIDGETIC_PARTNER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflowId": "WORKFLOW_ID",
    "title": "Welcome, then an offer",
    "description": "A welcome page that leads to an offer.",
    "position": 1
  }'
```

| Field | What it is |
| - | - |
| `key` (in the address) | The name your code uses: 1 to 64 lowercase letters, digits, hyphens and underscores, starting with a letter or a digit, such as `welcome-then-offer` |
| `workflowId` | **Required.** One of your own published workflows |
| `title` | What the list of starting points shows, up to 120 characters. Without one, it shows the workflow's name |
| `description` | Up to 500 characters |
| `position` | 0 to 10000, and 0 when left out. The list comes back with the smallest first, then by key |

* **Sending the same key again replaces it.** The call answers `200` both times, so it is safe to repeat and needs no `Idempotency-Key`. It replaces the whole starting point: a `title`, `description` or `position` you leave out goes back to its default.
* **What customers get is the live version as it is when they start.** Publishing the workflow changes what the next start gets, so look at a new version before you publish it.
* **Your key makes the call,** or the owner of your partner, signed in on widgetic.com. An [editor session](https://docs.widgetic.com/docs/partners/editor-sessions.md) cannot: it is for your server.

### Read and remove

`GET /partners/{partnerId}/workflow-presets` lists what you offer, ordered by `position` and then by `key`. Each one says what it is made from and whether customers can start from it now:

```json theme={"theme":"css-variables"}
{
  "success": true,
  "data": {
    "items": [
      {
        "key": "welcome-then-offer",
        "workflowId": "5c1d2e3f-4a5b-4c6d-8e7f-90a1b2c3d4e5",
        "title": "Welcome, then an offer",
        "description": "A welcome page that leads to an offer.",
        "position": 1,
        "available": true,
        "unavailableReason": null,
        "workflowName": "Welcome journey",
        "blockCount": 4,
        "widgets": [
          {
            "id": "4b2f9c1e-6d3a-4f08-9a57-1c2e8b7d5a30",
            "name": "Welcome page",
            "thumbnailUrl": "https://cdn.widgetic.com/widgets/4b2f9c1e-6d3a-4f08-9a57-1c2e8b7d5a30/thumbnail.png?t=1795536526532"
          }
        ],
        "createdAt": "2026-10-28T12:00:00.000Z",
        "updatedAt": "2026-10-28T12:00:00.000Z"
      }
    ]
  }
}
```

A starting point that cannot be started has `available` set to `false`, and `unavailableReason` says why: `workflow_missing` (the workflow was deleted), `workflow_not_own`, `workflow_archived` (unarchive it), `workflow_not_published`, `workflow_empty`, `composition_not_own`, `too_many_widgets` or `widget_not_preset` (a widget it chains is no longer offered as a preset). A customer is never shown one that is not available, so read this list to notice a starting point that went stale.

`DELETE /partners/{partnerId}/workflow-presets/{key}` stops offering it and answers `{ "removed": true }`, or `false` (not an error) when nothing was offered under that key. It leaves the workflow, and every workflow a customer already started from it, alone. Deleting the workflow takes its starting point off the list too.

### When an offer is refused

The reason is in `error.details.reason`:

| Status | Code | `reason` | What it means |
| - | - | - | - |
| 404 | `RESOURCE_WORKFLOW_NOT_FOUND` | | The workflow does not exist, or is not one of your account's own (the two look the same) |
| 409 | `BUSINESS_STATE_CONFLICT` | `workflow_archived` | It is archived. Unarchive it first |
| 409 | `BUSINESS_STATE_CONFLICT` | `workflow_not_published` | It was never published. A starting point is what visitors get, never a draft |
| 409 | `BUSINESS_STATE_CONFLICT` | `workflow_already_offered` | It is already offered, under the key in `details.key`. Remove that one, or replace it |
| 409 | `BUSINESS_STATE_CONFLICT` | `too_many_presets` | You already offer 50 (`details.limit`). Remove one first |
| 409 | `BUSINESS_STATE_CONFLICT` | `preset_changed_meanwhile` | Another change to your starting points landed at the same moment. Ask again |
| 422 | `BUSINESS_OPERATION_INVALID` | `workflow_empty` | It shows no composition |
| 422 | `BUSINESS_OPERATION_INVALID` | `composition_not_own` | A block shows a composition made for a customer or for a team |
| 422 | `BUSINESS_OPERATION_INVALID` | `too_many_widgets` | It chains more than 10 widgets (`details.limit`) |
| 422 | `BUSINESS_OPERATION_INVALID` | `widget_not_preset` | A widget it chains is not one of your preset widgets. `details.widgets` lists them, each with its `id` and `name`, so that you can offer them first |

### Start one

Your server starts one for a customer with two calls, made with your key and the customer's header (see [From your server](#from-your-server)): the list of what this customer is offered, which you draw on your own page, and the start itself, which makes the copies and the new draft. Then open the new workflow in the screen: give the screen its `id` (the answer of the start has it) as `workflowId`, when you mount it or with `workflows.module.setWorkflow(workflowId)` on a screen that is on show.

```bash theme={"theme":"css-variables"}
# What this customer is offered
curl -sS "https://api.widgetic.com/v1/workspaces/$WIDGETIC_PARTNER_WORKSPACE_ID/workflows/presets" \
  -H "Authorization: Bearer $WIDGETIC_PARTNER_KEY" \
  -H "X-Managed-User-Id: $MANAGED_USER_ID"

# A workflow of the customer's own, started from one of yours
curl -sS -X POST "https://api.widgetic.com/v1/workspaces/$WIDGETIC_PARTNER_WORKSPACE_ID/workflows/from-preset" \
  -H "Authorization: Bearer $WIDGETIC_PARTNER_KEY" \
  -H "X-Managed-User-Id: $MANAGED_USER_ID" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "key": "welcome-then-offer", "name": "Our welcome journey" }'
```

Send the customer's header on both calls. Without it they are your own account's, and the list holds what Widgetic offers to everyone with a Widgetic account, not your starting points.

The list holds only what can be started now, in your order, and shows nothing about who made it and no id of its own:

```json theme={"theme":"css-variables"}
{
  "success": true,
  "data": {
    "items": [
      {
        "key": "welcome-then-offer",
        "title": "Welcome, then an offer",
        "description": "A welcome page that leads to an offer.",
        "blockCount": 4,
        "widgets": [{ "name": "Welcome page", "thumbnailUrl": "https://cdn.widgetic.com/widgets/4b2f9c1e-6d3a-4f08-9a57-1c2e8b7d5a30/thumbnail.png?t=1795536526532" }]
      }
    ]
  }
}
```

* **`key` is the one the list gives, and `name` is optional.** It is up to 120 characters. Without it, the new workflow is named after the starting point's title.
* **The answer is `201` with the new workflow,** a draft, as for any new workflow. Its `id` is the `workflowId` to open it with.
* **Send an `Idempotency-Key`.** A start takes a few seconds, because every widget is copied, and an answer lost to a timeout is then repeated and not made twice.
* **A start that is not offered to this customer, or can no longer be started, is `404`** with `RESOURCE_WORKFLOW_PRESET_NOT_FOUND`. The customer cannot fix it, and a half-made copy would be worse, so it reads as missing.
* **A start that fails leaves nothing to clean up.** The answer is `503` with `SERVICE_UNAVAILABLE` and `reason: "preset_copy_failed"`: the compositions it made are removed again, so asking again is safe. The copies of widgets it made stay in the customer's account as ordinary widgets, which they can delete like any other.
* **Your webhook is told** (`workflow.created`, with `presetKey` set to the key). See [What you are told](#what-you-are-told).

## Show a workflow on a page

The screen has an **Embed code** button only when your page listens for `showEmbedCode` at the moment it mounts, and only for a workflow that has been published. It tells your page which workflow, and your page shows the tag: the tag of the workflow's first composition, with `workflow-id` added (see [Show a path of compositions in one place](https://docs.widgetic.com/docs/api/embedding-workflows.md#show-a-path-of-compositions-in-one-place)).

A published workflow tells anyone which composition a new visitor starts on, so your page can read it without a key:

```javascript theme={"theme":"css-variables"}
async function showMyEmbedCodeDialog(workflowId) {
  try {
    const answer = await fetch(`https://api.widgetic.com/embed/workflows/${workflowId}`);
    if (!answer.ok) throw new Error(`The workflow could not be read (${answer.status})`);

    const { data: published } = await answer.json(); // every answer of the API is { success, data }
    // A paused workflow answers with its status and nothing else: there is no first composition to name.
    if (!published.startCompositionId) return showMessage('Resume the workflow to get its embed code.');

    showCode(
      `<widgetic workflow-id="${workflowId}" composition-id="${published.startCompositionId}" ` +
        `resize="fill-width" width="800" embed-target="site"></widgetic>`,
    );
  } catch (error) {
    console.error('[workflows] Could not build the embed code', error);
    showMessage('The embed code is not available right now.');
  }
}
```

* **The tag goes on a page that has the Embed SDK on it,** as for any widget. The visitors on that page need no account and sign in to nothing.
* **A visitor's position stays in their own browser.** See [Show a path of compositions in one place](https://docs.widgetic.com/docs/api/embedding-workflows.md#show-a-path-of-compositions-in-one-place) for what a visitor's browser keeps and what it tells your page.
* **Counts reach the screen.** What the tag reports (how many visitors reached a block or took a line) is what the customer reads in **Runs**.

## From your server

Everything the screen does, your server can do with your API key, for one customer at a time: the same calls, on the same addresses, with the customer named in a header. Send `X-Managed-User-Id` (Widgetic's id for the managed user) or `X-Managed-User-External-Id` (your own `externalId`), one of the two, and the id of your partner workspace as the workspace (`$WIDGETIC_PARTNER_WORKSPACE_ID` below). Everything your customers make is filed in your partner workspace, and its id is the `workspaceId` that the answer of an [editor session](https://docs.widgetic.com/docs/partners/editor-sessions.md) carries.

```bash theme={"theme":"css-variables"}
# The customer's workflows
curl -sS "https://api.widgetic.com/v1/workspaces/$WIDGETIC_PARTNER_WORKSPACE_ID/workflows" \
  -H "Authorization: Bearer $WIDGETIC_PARTNER_KEY" \
  -H "X-Managed-User-Id: $MANAGED_USER_ID"

# A new workflow for the customer, started from one of their compositions
curl -sS -X POST "https://api.widgetic.com/v1/workspaces/$WIDGETIC_PARTNER_WORKSPACE_ID/workflows" \
  -H "Authorization: Bearer $WIDGETIC_PARTNER_KEY" \
  -H "X-Managed-User-Id: $MANAGED_USER_ID" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Welcome journey", "compositionId": "COMPOSITION_ID" }'
```

With the TypeScript SDK the header is an argument of the call: `xManagedUserId`, or `xManagedUserExternalId` for your own id.

```typescript theme={"theme":"css-variables"}
import { WorkflowsApi } from '@widgetic/api-sdk-ts';

const workflowsApi = new WorkflowsApi(process.env.WIDGETIC_PARTNER_KEY!);

// Widgetic's id for the managed user, and the id of your partner workspace (the `workspaceId` of an editor session)
const managedUserId = 'MANAGED_USER_ID';
const partnerWorkspaceId = 'PARTNER_WORKSPACE_ID';

// The customer's workflows
const { data: workflowList } = await workflowsApi.listWorkspaceWorkflows({
  workspaceId: partnerWorkspaceId,
  xManagedUserId: managedUserId,
});

console.log(`${workflowList.total} workflows, showing ${workflowList.items.length}`);
```

The calls are in the [API reference](https://docs.widgetic.com/api-reference/introduction.md) under Workflows. They are: the list, making a workflow, reading, saving and deleting one, duplicating, publishing, discarding changes, the versions and restoring one, pausing, resuming, archiving and unarchiving, the counts of runs, the compositions a workflow can start from, and the starting points a customer is offered and starting one from them (see [Start one](#start-one)). The calls you make about your own starting points are under Workflows too, and under Partners (see [Offer one](#offer-one)). Making, duplicating, starting from a starting point and publishing a workflow take an `Idempotency-Key`, as the reference says (see [Idempotency](https://docs.widgetic.com/docs/reference/idempotency.md)). Saving a workflow takes the `revision` you read, so that two writers do not overwrite each other.

Your key reaches no more through the header than the screen does through a session:

* **The customer is the one in the header, and nothing else.** A body or a query that names a customer, an organization or another owner changes nothing: the workflow is filed under the customer in the header, for good.
* **The customer's workflows only.** A workflow of another customer, one you made without a header, one of another account and one that does not exist all answer `404` with `RESOURCE_WORKFLOW_NOT_FOUND`, so you cannot tell them apart. A workflow chains the compositions filed under that customer only: another composition answers `404` with `RESOURCE_COMPOSITION_NOT_FOUND`, and a draft that holds one cannot be published.
* **The workspace is your partner workspace.** The id of another workspace answers `404` with `RESOURCE_WORKSPACE_NOT_FOUND`, and a word where the id belongs (`me`, say) answers `403` with `MANAGED_USER_SCOPE_ROUTE_NOT_AVAILABLE`, as does any call that does not take the header.
* **The customer must be yours, and the key a partner's.** An id that is not one of your managed users, or is another partner's, answers `404` with `MANAGED_USER_NOT_FOUND`, and so does any API key that is not a partner's, because only a partner has managed users. A call that is not made with an API key (a signed-in person, say) answers `403` with `MANAGED_USER_SCOPE_NOT_ALLOWED`. An empty, repeated or malformed header is `400` with `MANAGED_USER_SCOPE_INVALID`.
* **A customer you switched off** keeps its workflows, and you can still read and change them, but you cannot make, copy or start one for it: `409` with `MANAGED_USER_INACTIVE`.
* **The cost is the same.** No credits (see [Limits and cost](#limits-and-cost)).

Without the header, the call is your own account's, as it always was: it sees every customer's workflows next to yours. The two calls for starting points are the one place where that does not mean "everything": without the header they show what Widgetic offers to everyone, not your starting points (see [Start one](#start-one)).

Keep your key on your server. A page in a browser uses an [editor session](#make-a-session) instead.

## What you are told

Your webhook can be told when a customer makes, publishes, changes or deletes a workflow, with or without the screen:

| Event | When |
| - | - |
| `workflow.created` | A workflow was created for a customer: new, copied from another of theirs, or started from one of your starting points (`presetKey` says which, and is `null` for the others) |
| `workflow.published` | A workflow was published as a new version |
| `workflow.state_changed` | A workflow was paused, resumed, archived or unarchived |
| `workflow.deleted` | A workflow was deleted, in whatever state it was, with its versions and counts |

They are about your customers' workflows only: what you make yourself, in your own account, is not told. They carry the ids and the names, and none of the workflow's blocks, so read the workflow for what it holds now. A deleted workflow can no longer be read, so `workflow.deleted` carries its name and the state it was in. A webhook that receives every event receives these too, and one that lists its events needs them added. What each one carries is in the [API reference](https://docs.widgetic.com/api-reference/events/workflow-created.md), and [Events](https://docs.widgetic.com/docs/webhooks/events.md) lists them all.

## Errors

The screen handles these for you and tells your page (`error` event). The ones of the session itself are in [Errors](https://docs.widgetic.com/docs/partners/editor-sessions.md#errors).

| Status | Code | Meaning | What to do |
| - | - | - | - |
| 403 | `EDITOR_SESSION_ROUTE_NOT_ALLOWED` | The call is not one a session may make: a `workspaceId` that is not an id (`me`, for one), or a path that is not one of the workflow calls | Mount the screen with the id of your partner workspace, the `workspaceId` an editor session answers with |
| 403 | `EDITOR_SESSION_FIELD_NOT_ALLOWED` | The request sets a field a session may not set | Not caused by the screen. Remove the field when you call the API yourself |
| 403 | `MANAGED_USER_SCOPE_ROUTE_NOT_AVAILABLE` | Your key named a customer on a call that is not a workflow call of your partner workspace (or put a word where the workspace id belongs) | Use the id of your partner workspace, or leave the header out for a call that is not about one customer |
| 403 | `MANAGED_USER_SCOPE_NOT_ALLOWED` | A customer header came with a credential that is not an API key, such as a signed-in person's | Send the header from your server, with your partner key |
| 404 | `RESOURCE_WORKSPACE_NOT_FOUND` | The workspace id in the path is not your partner workspace (the one an editor session answers with) | Use your partner workspace's id |
| 404 | `RESOURCE_WORKFLOW_NOT_FOUND` | The workflow is not this customer's, or does not exist | Check which customer the session was made for |
| 404 | `RESOURCE_COMPOSITION_NOT_FOUND` | A workflow was started from a composition that is not this customer's | File the composition under the customer (see [Filing Content Under a Managed User](https://docs.widgetic.com/docs/partners/managed-users.md#filing-content-under-a-managed-user)) |
| 404 | `RESOURCE_WORKFLOW_PRESET_NOT_FOUND` | A start named a starting point that is not offered to this customer, or that can no longer be started | Read the list again and start one of those (see [Start one](#start-one)) |
| 404 | `MANAGED_USER_NOT_FOUND` | The customer in the header is not one of your managed users, or the key is not a partner's (only a partner has managed users) | Check the id or the `externalId`, and send your partner key |
| 409 | `MANAGED_USER_INACTIVE` | You tried to make, copy or start a workflow for a customer you switched off | Switch the customer on, or make the workflow without the header |
| 409 | `BUSINESS_STATE_CONFLICT` | You offered a workflow that cannot be offered now (archived, never published, already offered), or you already offer 50 (`details.reason` says which) | See [When an offer is refused](#when-an-offer-is-refused) |
| 422 | `BUSINESS_OPERATION_INVALID` | The draft cannot be published as it is (`details.issues` names what to fix), or the workflow you offered cannot be given away as it is (`details.reason` says why) | Fix the block, or see [When an offer is refused](#when-an-offer-is-refused) |
| 503 | `SERVICE_UNAVAILABLE` | A start could not set up the starting point right now (`details.reason` is `preset_copy_failed`) | Ask again: nothing was left that you must clean up (see [Start one](#start-one)) |

`MANAGED_USER_SCOPE_ROUTE_NOT_AVAILABLE`, `MANAGED_USER_SCOPE_NOT_ALLOWED`, `MANAGED_USER_NOT_FOUND` and `MANAGED_USER_INACTIVE` come only to a call made with a customer header, which your server sends with your key: the screen cannot cause them.

## Next Steps

> [card] [Editor Sessions](https://docs.widgetic.com/docs/partners/editor-sessions.md)
>
> Make sessions, and what a session can do

> [card] [UI Components](https://docs.widgetic.com/docs/partners/ui-components)
>
> The SDK, tokens, the look and the language of every piece

> [card] [Managed Users](https://docs.widgetic.com/docs/partners/managed-users.md)
>
> File your customers' content under them

> [card] [Embed a workflow](https://docs.widgetic.com/docs/api/embedding-workflows.md)
>
> What a workflow does on a page

> [card] [Notifications](https://docs.widgetic.com/docs/partners/notifications.md)
>
> Be told when a customer makes or publishes a workflow


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