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

> ## Agent Instructions
> Start with https://docs.scrip.dev/agents.md and https://docs.scrip.dev/which-endpoints-you-need.md. Your application only needs a few API calls as users earn and spend (`POST /v1/events`, balance/history reads, and redemptions); program setup happens in the dashboard or setup scripts.
> Use `https://api-sandbox.scrip.dev` with `sk_test_` keys for testing, and `https://api.scrip.dev` with `sk_live_` keys for production. Keep API keys on your server.
> Pass your own user ID as `external_id` on events and prefix it with `ext:` in participant URL paths (e.g., `GET /v1/participants/ext:user_123/balances`). By default (`on_unknown_participant: CREATE`), the first event for a new `external_id` creates and enrolls the participant automatically.
> Events process asynchronously: `POST /v1/events` returns `202 Accepted` when queued, and rules evaluate in the background. Pass an `idempotency_key` (such as an order ID) on every event, and wait for the `event.completed` webhook or poll `GET /v1/events/{event_id}` before reading updated balances.
> Connect the hosted MCP server at https://mcp.scrip.dev/mcp (OAuth, defaults to Sandbox) to inspect programs, validate and simulate rules, and trace events. Append `.md` to any docs URL for Markdown, or fetch https://docs.scrip.dev/openapi.json for full endpoint schemas.

# Folders

> Organize programs within an organization into a hierarchy up to 8 levels deep

Folders organize programs and nested subfolders within a single organization, up to 8 levels deep. Use them to group programs by brand, region, franchise, or business line for filtering and [folder-scoped reporting](https://docs.scrip.dev/guides/reporting.md#scoping-reports-by-folder).

Folders are optional organizational metadata. Programs without a folder live at the top level, and placing a program in a folder has no effect on its rules, linked assets, or participant balances.

## Folders vs. separate organizations

| Need | Use |
| - | - |
| Multiple brands, regions, or locations that share end users, cross-program rules, or unified reporting | **Folders** inside one organization. A customer active across brands is one participant with shared counters, tags, and attributes. |
| Independent companies with separate dashboard logins, API keys, participants, and assets | **Separate organizations**. Nothing is shared across organization boundaries. |

## Creating a folder

```bash theme={null}
POST /v1/folders
```

```json theme={null}
{
  "name": "Coffee",
  "kind": "brand",
  "external_id": "brand-coffee",
  "metadata": {"region": "west"}
}
```

The API returns `201 Created` with the folder:

```json theme={null}
{
  "id": "1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c331",
  "name": "Coffee",
  "kind": "brand",
  "external_id": "brand-coffee",
  "metadata": {"region": "west"},
  "status": "ACTIVE",
  "created_at": "2027-01-15T10:00:00Z",
  "updated_at": "2027-01-15T10:00:00Z"
}
```

| Field | Required | Description |
| - | - | - |
| `name` | Yes | Display name (1-255 characters), unique per parent folder (case-insensitive) |
| `parent_folder_id` | No | Active parent folder ID. Omit for a top-level folder (level 1). Maximum depth is 8 levels. |
| `kind` | No | Optional level classification (max 64 characters), such as `brand` or `region`. Informational only. |
| `external_id` | No | Your external identifier (max 255 characters), unique across folders in your organization |
| `metadata` | No | Key-value string [labels](#labels) |

## Depth, names, and IDs

* **Depth:** Folders nest up to 8 levels deep, with top-level folders at level 1.
* **Name uniqueness:** Folder names are unique among siblings under the same parent (case-insensitive). Program names are unique within their folder or among top-level programs (case-insensitive), so two different brand folders can each contain a `Downtown` program. Uniqueness is checked on create, rename, and move.
* **External IDs:** `external_id` is unique across the organization separately for folders and for programs, including archived resources.

See [Limits](https://docs.scrip.dev/limits.md) for character and label size bounds.

## Organizing programs in folders

A multi-brand business can model divisions, brands, and store-level programs as a tree:

```text theme={null}
Food and drink (kind: division)
├── Coffee (kind: brand)
│   ├── Downtown (program, external_id: store-101)
│   └── Airport  (program, external_id: store-102)
└── Bakery (kind: brand)
    └── Downtown (program, external_id: store-201)
```

Create a program inside an active folder by passing `folder_id` on `POST /v1/programs`:

```bash theme={null}
POST /v1/programs
```

```json theme={null}
{
  "name": "Downtown",
  "folder_id": "1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c331",
  "external_id": "store-101",
  "metadata": {"format": "cafe"}
}
```

When importing many programs, setting `external_id` makes reruns safe to resume: a duplicate returns `409 program_external_id_already_exists` so your script can skip already-created programs.

Folders control organization, list filtering, and report scoping, while asset linking controls where points can be earned and redeemed. To keep Coffee points and Bakery points separate while sharing participant counters across both brands:

* Create one [asset](https://docs.scrip.dev/guides/asset-configuration.md) per brand (`COFFEE`, `BAKERY`) and link it only to that brand's programs (`POST /v1/assets` links up to 1,000 programs via `program_ids`; link additional programs with `POST /v1/programs/{program_id}/assets`).
* Attempts to redeem `COFFEE` through a Bakery program fail with `422 asset_not_linked`.
* Participant counters, tags, and attributes remain organization-scoped, so rules in any program can read cross-brand totals such as `lifetime_spend`. See [Multi-program balances](https://docs.scrip.dev/guides/multi-program-balances.md) and [State management](https://docs.scrip.dev/guides/state-management.md).

> [!NOTE]
>
> Asset links cannot be removed once created. Verify a program's linked assets with `GET /v1/programs/{program_id}/assets` before going live.

## Filtering folders and programs

Pass `folder_id` to `GET /v1/programs` to list programs in a folder and all of its nested subfolders:

```bash theme={null}
GET /v1/programs?folder_id=1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c331
```

| Parameter | Behavior on `GET /v1/programs` |
| - | - |
| `folder_id` | Returns programs in the folder and every descendant folder. |
| `direct_only=true` | Combined with `folder_id`, returns only programs directly in that folder (excludes subfolders). |
| `external_id` | Returns the program with that exact `external_id`. Archived programs require `include_archived=true` or `status=ARCHIVED`. |
| `label` | Exact `key:value` match against `metadata` (one label per request), such as `label=format:cafe`. Escape a colon in the key as `\:` and a backslash as `\\`. |

Use `GET /v1/folders` to list folders, filtered by `parent_folder_id` (pass `null` for top-level folders), `kind`, `external_id`, `status`, or `search`. Unlike `GET /v1/programs`, omitting `status` on `GET /v1/folders` returns both `ACTIVE` and `ARCHIVED` folders.

`GET /v1/folders/{folder_id}` returns the folder with its `ancestors` array ordered from the top-level folder down to its immediate parent, useful for rendering breadcrumbs:

```json theme={null}
{
  "id": "1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c331",
  "name": "Coffee",
  "parent_folder_id": "1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c333",
  "kind": "brand",
  "external_id": "brand-coffee",
  "metadata": {"region": "west"},
  "status": "ACTIVE",
  "created_at": "2027-01-15T10:00:00Z",
  "updated_at": "2027-02-01T09:00:00Z",
  "ancestors": [
    {"id": "1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c333", "name": "Food and drink", "kind": "division", "status": "ACTIVE"}
  ]
}
```

To aggregate liability, activity, or fulfillment reports across a folder's programs, pass the same `folder_id` to any supported reporting endpoint. See [Scoping reports by folder](https://docs.scrip.dev/guides/reporting.md#scoping-reports-by-folder).

## Labels

Folders and programs both store custom key-value string pairs in `metadata` (for example, `{"region": "west"}`). On `PATCH`, `metadata` replaces all existing labels, so include every key you want to keep. Send `{}` to clear all labels; sending `null` returns `400`. See [Limits](https://docs.scrip.dev/limits.md) for key and length caps.

## Moving folders and programs

Moving a folder moves its entire subtree of subfolders and programs. Send the target active `parent_folder_id` (or `null` to promote to top level) on `PATCH /v1/folders/{folder_id}`:

```bash theme={null}
PATCH /v1/folders/1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c331
```

```json theme={null}
{
  "parent_folder_id": "1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c333"
}
```

A folder move is rejected when:

* The target parent does not exist (`404 folder_not_found`) or is archived (`409 folder_archived`).
* The target parent is the folder itself or one of its descendants (`422 folder_cycle`).
* Any descendant would exceed the 8-level depth limit (`422 folder_too_deep`).
* A sibling under the target parent already uses the same name (`409 folder_name_already_exists`).

`parent_folder_id` and `status` cannot be sent in the same `PATCH /v1/folders/{folder_id}` request.

To move a program, send `folder_id` (or `null` for top level) on `PATCH /v1/programs/{program_id}`:

```bash theme={null}
PATCH /v1/programs/8f14e45f-ceea-4e70-9df8-2a7d1b3c9f02
```

```json theme={null}
{
  "folder_id": "1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c331"
}
```

Moving a program updates only its folder assignment. Its linked assets, balances, and rules remain unchanged.

### Reassigning a program that needs a different asset

Because asset links cannot be removed, do not move a program into a folder whose brand uses a different asset (for example, rebranding a Coffee store as a Bakery store). Instead, create a new program:

1. Clear the old program's `external_id` via `PATCH /v1/programs/{program_id}` with `{"external_id": null}` so the new program can reuse it (archived programs retain their `external_id`).
2. Create the replacement program in the target folder with the store's `external_id`, link it to the new brand's asset, and add its rules.
3. Archive the old program via `PATCH /v1/programs/{program_id}` with `{"status": "ARCHIVED"}`.

Existing participants retain their balances in the original asset and can continue redeeming them at other programs linked to that asset.

## Archiving and restoring folders

Folders cannot be deleted. Archive bottom-up: every subfolder and program under the folder (including `SUSPENDED` programs) must be `ARCHIVED` before you can archive the folder itself.

```bash theme={null}
PATCH /v1/folders/1c4e6a8b-3d52-4f79-8a10-b6d8f0a2c331
```

```json theme={null}
{"status": "ARCHIVED"}
```

If unarchived contents remain, the API returns `409 folder_has_unarchived_contents` with `unarchived_folders` and `unarchived_programs` counts in `details`.

While a folder is `ARCHIVED`:

* It cannot accept new subfolders, moved folders, or programs (`409 folder_archived`).
* Programs inside it cannot be set to `ACTIVE` or `SUSPENDED` (`409 program_folder_archived`). Restore the folder or move the program to an active folder first.

Send `{"status": "ACTIVE"}` to restore a folder. Restoring requires the folder to be top-level or its parent to be `ACTIVE` (`409 folder_parent_archived` otherwise), and does not automatically restore archived programs inside it.

> [card] [Scoping reports by folder](https://docs.scrip.dev/guides/reporting.md#scoping-reports-by-folder)
>
> Roll up liability, activity, and fulfillment cost across a folder tree.

> [card] [Multi-program balances](https://docs.scrip.dev/guides/multi-program-balances.md)
>
> Choose between pooled and partitioned balances when assets span programs.

> [card] [Folders API reference](https://docs.scrip.dev/api-reference/folders/overview.md)
>
> Endpoints, parameters, and response schemas for folders.


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