> ## 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.

# Widgets

> List, create and manage widgets via the API

Widgets are the core building blocks in Widgetic. Each widget is a self-contained, configurable UI component that can be embedded anywhere.

## Overview

With the Widgets API, you can:

* List the widgets your account owns, one page at a time
* Create a widget
* Batch fetch up to 50 widgets by ID

## List Widgets

`GET /widgets` lists the widgets your account owns, newest first. Pass `page` (counting from 1) and `size` (1 to 100, 20 when left out) to read the list one page at a time.

```bash cURL theme={"theme":"css-variables"}
curl "https://api.widgetic.com/v1/widgets?page=1&size=20" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

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

const widgets = new WidgetsApi('YOUR_API_KEY');

const { data, meta } = await widgets.getWidgets({
  page: 1,
  size: 20
});

console.log(`Showing ${data.length} of ${meta?.total} widgets`);
```

`meta` carries the figures you need to walk the list:

```json theme={"theme":"css-variables"}
{
  "success": true,
  "data": [
    { "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "name": "Quarterly sales chart" }
  ],
  "meta": {
    "page": 1,
    "size": 20,
    "total": 134,
    "limit": 20,
    "offset": 0,
    "hasNextPage": true,
    "hasPreviousPage": false
  }
}
```

A page past the end is an empty list, not an error.

> [!WARNING]
>
> Without `page` and `size`, the call returns the whole list in one response. That only suits an account with a few widgets: for a large one the response can be cut short, and nothing in it says so. If you do not know how many widgets an account holds, always page.

To read every widget, keep asking for the next page until `meta.hasNextPage` is `false`:

```typescript theme={"theme":"css-variables"}
async function* allWidgets() {
  for (let page = 1; ; page++) {
    const { data, meta } = await widgets.getWidgets({ page, size: 100 });
    yield* data;
    if (!meta?.hasNextPage) return;
  }
}

for await (const widget of allWidgets()) {
  console.log(`${widget.name} (${widget.id})`);
}
```

### The Widget on a Canvas

A canvas holds one widget. Pass `canvasId` to find the widget on one of your canvases: the list has that one widget, or none while the canvas is empty. It is always returned whole, whatever `page` and `size` say.

```typescript theme={"theme":"css-variables"}
const { data: onThisCanvas } = await widgets.getWidgets({
  canvasId: '9f0c6b54-3e8f-4a2a-8b7d-1c5c6d9e0a1b'
});
```

### Widgets for One Managed User

This is for partners. Managed users exist only on a partner's account, and working with them takes an active partner API key (see [Managed Users](https://docs.widgetic.com/docs/partners/managed-users.md)); no other key can make a managed user or file anything under one.

If you file widgets under your customers (see [Managed Users](https://docs.widgetic.com/docs/partners/managed-users.md#filing-content-under-a-managed-user)), pass `managedUserId` (Widgetic's id for the managed user) or `managedUserExternalId` (your own id for them) to list only that customer's widgets. Send one of them, never both. It combines with `page`, `size` and `canvasId`, and it only narrows the list to your own account's widgets.

```bash theme={"theme":"css-variables"}
curl "https://api.widgetic.com/v1/widgets?managedUserExternalId=your-platform-user-123&page=1&size=20" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

A managed user that is not one of yours answers `404` with the code `MANAGED_USER_NOT_FOUND`. With a key that is not a partner's, that is every managed user.

> [!NOTE]
>
> The list takes no `sort` parameter, and no filter other than `canvasId` and the managed user: it is always newest first.

## Create a Widget

`POST /widgets` creates a widget for your account: a named record with a type and some starting content, on a canvas of its own (or on an empty canvas of yours that you name: a canvas holds one widget). It costs no credits and has no code yet; the code is generated for it afterwards. A widget is a draft until you send `isDraft: false`.

```bash cURL theme={"theme":"css-variables"}
curl -X POST "https://api.widgetic.com/v1/widgets" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 7b1d5a52-2f3c-4f0e-9a58-5d3b7a6a9c11" \
  -d '{
    "name": "Quarterly sales chart",
    "type": "chart",
    "content": { "chartType": "bar" }
  }'
```

```typescript TypeScript theme={"theme":"css-variables"}
import { randomUUID } from 'node:crypto';

// The API needs an Idempotency-Key header: send it as idempotencyKey in the request object.
// Keep the key if you retry, so that one widget is created, not two.
const idempotencyKey = randomUUID();

const { data: widget } = await widgets.createWidget({
  idempotencyKey,
  newWidget: {
    name: 'Quarterly sales chart',
    type: 'chart',
    content: { chartType: 'bar' }
  }
});

console.log(`Created ${widget.id}`);
```

The response has status `201` and carries the new widget in `data` (shortened here):

```json theme={"theme":"css-variables"}
{
  "success": true,
  "data": {
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "name": "Quarterly sales chart",
    "type": "chart",
    "isDraft": true,
    "isPublic": false,
    "canvasId": "9f0c6b54-3e8f-4a2a-8b7d-1c5c6d9e0a1b",
    "createdAt": "2026-10-02T12:00:00.000Z"
  }
}
```

### Fields

| Field | Required | Description |
| - | - | - |
| `name` | Yes | Name of the widget |
| `type` | Yes | What kind of widget this is, a label of your choosing (for example `chart`, `form`, `gallery`) |
| `content` | Yes | Starting content, as an object. `{}` is fine |
| `isPublic` | No | Whether the widget is public. Default `false` |
| `isDraft` | No | Whether the widget starts as a draft. Default `true` |
| `canvasId` | No | Put the widget on this existing canvas instead of a new one. You must own the canvas, and it must have no widget yet: a canvas holds one widget, and one that already has a widget is refused with `409` and the code `CANVAS_ALREADY_HAS_WIDGET` |
| `projectId` | No | Project to file the widget in. You must be able to edit the project |
| `organizationId` | No | Workspace the widget belongs to (the API calls a workspace an organization). You must be a member who may create widgets there |
| `managedUserId` | No | Partners only, with an active partner API key. File the widget under this managed user (Widgetic's id for the user). Send this or `managedUserExternalId`, not both. The managed user must be one of yours and switched on |
| `managedUserExternalId` | No | Partners only. The same, by the `externalId` you registered the managed user with |

Only the fields above are used. Anything else in the body is ignored, with one exception: `managed_user_id` and `managed_user_external_id` are refused with `400 MANAGED_USER_REFERENCE_INVALID`, so that a widget meant for a customer is never created without one. The answer carries `managedUserId`. An update does not change it: move the widget to another customer, or take the label off, with `PUT` or `DELETE /widgets/{id}/managed-user` (the canvas the widget sits on follows it). See [Managed Users](https://docs.widgetic.com/docs/partners/managed-users.md#filing-content-under-a-managed-user) for the checks Widgetic makes, and [Moving Content to Another Managed User](https://docs.widgetic.com/docs/partners/managed-users.md#moving-content-to-another-managed-user).

### Where a Widget Can Go

`canvasId`, `projectId` and `organizationId` must name something you may use. Naming anything else is refused with `403`, and the answer is the same whether the id exists or not, so it never tells you whether an id you guessed is real.

A canvas holds one widget at a time, so `canvasId` must name a canvas that has none yet. A canvas of yours that already has a widget is refused with `409` and the code `CANVAS_ALREADY_HAS_WIDGET`, and nothing is created. Leave `canvasId` out to give the widget a canvas of its own, which is what you want unless you are filling a canvas you made empty.

### Warnings

If the widget was created without all of its parts (for example, its canvas could not be told that this is its main widget), `data.warnings` is a list of what did not go through. It is absent when everything did. Read it before relying on the widget.

### Retrying and Limits

* The `Idempotency-Key` header is required (`400` without it). Send the **same** value when you retry, so one widget is created, not two. See [Idempotency](https://docs.widgetic.com/docs/reference/idempotency.md).
* Creating a widget has a limit of its own: 120 per minute for each account, counted across all of that account's keys. Past that the API answers `429` with a `Retry-After` header. If you need more, ask Widgetic. See [Rate Limits](https://docs.widgetic.com/docs/reference/rate-limits.md).

## Batch Fetch Widgets

`POST /widgets/batch` returns up to 50 widgets by ID in one request. A widget that cannot be returned comes back in `errors`, with the reason, while the others still come back in `widgets`.

```typescript theme={"theme":"css-variables"}
const { data: batch } = await widgets.getWidgetsBatch({
  getWidgetsBatchRequest: {
    widgetIds: [
      '123e4567-e89b-12d3-a456-426614174000',
      '223e4567-e89b-12d3-a456-426614174001',
      '323e4567-e89b-12d3-a456-426614174002'
    ]
  }
});

batch.widgets?.forEach(widget => {
  console.log(`${widget.name}: ${widget.id}`);
});

// A line for each id that could not be returned, with the reason
console.log(batch.errors);
```

## Widget Structure

A widget in an answer carries these fields:

| Field | Type | What it holds |
| - | - | - |
| `id` | string | The widget's identifier |
| `name` | string | Display name |
| `description` | string or `null` | What the widget is for, when it has a description |
| `type` | string | What kind of widget this is, the label you gave it |
| `content` | object | The content the widget started from |
| `isDraft` | boolean | Whether the widget is a draft |
| `isPublic` | boolean | Whether the widget is public |
| `canvasId` | string or `null` | The canvas the widget is on. A canvas holds one widget |
| `thumbnailUrl` | string or `null` | The widget's thumbnail: a public image address, or `null` until Widgetic has made one (see [Thumbnails](#thumbnails)) |
| `thumbnailSvg` | string or `null` | A small line drawing of the widget, as SVG, or `null` until Widgetic has drawn one (see [Thumbnails](#thumbnails)) |
| `hasUnpublishedChanges` | boolean | `true` when the widget was published and has been saved since. A widget that was never published is `false` |
| `publishedAt` | string or `null` | When the widget was last published (an ISO timestamp), or `null` when it never was |
| `organizationId` | string or `null` | The workspace the widget belongs to (the API calls a workspace an organization) |
| `managedUserId` | string or `null` | The managed user the widget was filed under (partners only), or `null` when it is your own |
| `createdAt` | string | When the widget was created (an ISO timestamp) |
| `updatedAt` | string | When the widget was last changed (an ISO timestamp) |

An answer can carry other fields. They are for Widgetic's own apps and can change without notice, so read only the ones above.

## Thumbnails

A widget has two thumbnails for the tiles of a list, and Widgetic makes both. A little after the last build of a widget that has none, Widgetic opens the widget in a browser of its own and saves what it shows: that is `thumbnailUrl`, a picture of what the widget looks like. A few minutes after the last build, Widgetic also draws `thumbnailSvg`, a small line drawing of the widget that stays clear in a small tile. Until then each is `null`, and each stays `null` for a widget that was never built.

`thumbnailUrl` is a public image address: use it as the `src` of an `img`. It changes when the picture is replaced, for example when the widget is published, so read the widget again rather than keeping the address. `thumbnailSvg` is the drawing itself, as SVG text on a 32 by 32 canvas, drawn in `currentColor`, so the colour is yours. Show it as a mask, 32 pixels wide, in the middle of a tile. A widget need not have one: when it is `null`, show `thumbnailUrl`.

A composition has no thumbnail of its own. It shows the thumbnail of its widget, which the composition's `widgetId` names, so every composition made from one widget shows the same picture. To draw a tile for each of a customer's widgets and compositions, see [Thumbnails of Widgets and Compositions](https://docs.widgetic.com/docs/partners/managed-users.md#thumbnails-of-widgets-and-compositions).

## Widget Lifecycle

```mermaid theme={"theme":"css-variables"}
flowchart LR
    Create[Create Widget] --> Edit[Edit on Canvas]
    Edit --> Build[Build & Publish]
    Build --> Embed[Embed on Site]
    Build --> Edit
```

## Widget Versions

Widgets keep a version history. A version is created when code is generated for the widget, and it becomes live when it is published.

## Embedding Widgets

A widget is shown on a page through a composition. Create a [composition](https://docs.widgetic.com/docs/api/compositions.md) on the widget, fill in its values, and put the embed code in your page:

```html theme={"theme":"css-variables"}
<script src="https://cdn.widgetic.com/sdks/browser/embed-sdk.js?v=6"></script>
<widgetic composition-id="COMPOSITION_ID" resize="fill-width" width="800" height="450" autoscale="on" adaptive="480" embed-target="site"></widgetic>
```

The widget needs a published version before it can be shown. Until then the public address answers `404`. See [Compositions](https://docs.widgetic.com/docs/api/compositions.md#embedding-compositions) for the attributes, and [Embedding widgets](https://docs.widgetic.com/docs/api/embedding.md) for the embed script.

## Related Endpoints

| Endpoint | Description |
| - | - |
| `GET /widgets` | List the widgets your account owns |
| `POST /widgets` | Create a widget |
| `POST /widgets/batch` | Batch fetch widgets |

## Next Steps

> [card] [Compositions](https://docs.widgetic.com/docs/api/compositions.md)
>
> Set a widget up for one place and embed it

> [card] [Canvases](https://docs.widgetic.com/docs/api/canvases.md)
>
> Edit the widget of a canvas


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