> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Sample Flows

## Article: Sample Flows

## Article Link: https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/sample-flows.md

## Article Content:

# Program Categories: Sample Flows

This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.

## Create or reuse categories

An app can reuse the site's existing Categories before creating the labels it needs. To resolve labels to Category IDs:

1. Call [List Categories](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/list-categories.md) with no `categoryIds` and set `x-wix-linguist` to the site's primary-language context (`<languageCode>|<locale>|true|<instanceId>`). The response contains all site Categories, up to 100.
2. Match the primary-language labels your app needs. Labels are unique within the site.
3. Call [Create Category](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/create-category.md) or [Bulk Create Categories](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/bulk-create-categories.md) only for missing labels.
4. For [Bulk Create Categories](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/bulk-create-categories.md), check each `results[].itemMetadata.success`. Use `itemMetadata.originalIndex` to match the result to the input, and handle `itemMetadata.error` for failures.
5. If `bulkActionMetadata.undetailedFailures` is greater than zero, call [List Categories](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/list-categories.md) again with no `categoryIds` and the same primary-language context. Compare original input labels without item details against the complete response. Reuse the ID of each matching Category and retry only inputs whose labels are still absent.
6. Save `itemMetadata.id` only for successful bulk results and the IDs found by label in the reconciliation read. For [Create Category](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/create-category.md), save the returned `category.id`. Use IDs, rather than labels, for Program assignments.

## Classify a new program

Create a Program, then assign its Categories. To prepare the Program:

### Part 1: Create the program

1. Call the Programs API to create the Program.
2. Save the returned Program ID.
3. Keep the Program's resulting Category set at or below 10 IDs.

### Part 2: Assign categories

Use the Program ID and the Category IDs from the previous steps:

1. Call [Bulk Assign Categories to Program](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/bulk-assign-categories-to-program.md) with the Program ID and the Category IDs in `categoriesToAssign`.
2. Don't include an ID in both `categoriesToAssign` and `categoriesToUnassign`.
3. Check each `results[].itemMetadata.success` and match its `itemMetadata.id` to the requested Category ID. A successful response can contain both successful and failed assignments.
4. Handle `itemMetadata.error` for failed items. If `bulkActionMetadata.undetailedFailures` is greater than zero, use [Get Category](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/get-category.md) to check the `assignedTo` value for unresolved IDs before retrying.
5. Wait for asynchronous synchronization with the Programs API only for successfully processed Category IDs. An immediate Programs API read may return the previous `categoryIds` value, so retry the read rather than resubmitting a successful assignment or unassignment. Handle failed IDs separately.

## Change a program's classification

An app can add and remove assignments in one request. After previous assignment changes have synchronized:

1. Compare the desired Category IDs with the Program's current `categoryIds`.
2. Put new IDs in `categoriesToAssign` and removed IDs in `categoriesToUnassign`.
3. Call [Bulk Assign Categories to Program](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/bulk-assign-categories-to-program.md) again and check each result as described above before waiting for synchronization.
4. To rename a Category, call [Update Category](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/update-category.md) with its current `revision`. The stable Category ID keeps Program relationships intact.

## Remove a category

A site owner can remove a Category from one Program or delete it across the site. Choose the operation that matches their intent:

1. To remove a Category from one Program, call [Bulk Assign Categories to Program](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/bulk-assign-categories-to-program.md) with its ID in `categoriesToUnassign`. Check the per-item result before waiting for synchronization.
2. To delete the reusable Category from the site, call [Delete Category](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/delete-category.md). Deletion asynchronously removes the Category ID from all associated Programs.

## Duplicate a program with category assignments

Duplicating a Program uses [Bulk Assign Categories to Program](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/bulk-assign-categories-to-program.md) to assign the original Program's Category IDs to the new Program. It reuses the existing Categories. To check the copied assignments:

1. Duplicate the Program through the Programs API and save the new Program's ID and the original Category IDs.
2. Retrieve each original Category with [Get Category](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/get-category.md) and check whether its `assignedTo` includes the new Program ID. The duplicated Program copies `categoryIds`, so that field alone doesn't confirm that each Category was updated.
3. For an assignment that remains absent, call [Bulk Assign Categories to Program](https://dev.wix.com/docs/api-reference/business-management/online-programs/categories/bulk-assign-categories-to-program.md) and check the per-item result. A successful duplication response alone doesn't confirm that every Category assignment succeeded.

## Build a public catalog

For a visitor- or member-facing category page, retrieve Programs with the Programs API so that Program visibility and access rules are applied. To load the page:

1. Use the Category ID selected for the page.
2. Query the Programs API with a filter on `categoryIds` and the visitor or member identity.
3. Display the returned Programs. `Category.assignedTo` doesn't apply Program visibility and access rules and must not be used as a public catalog.