> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# AddItemsToBenefit

# Package: benefitPrograms

# Namespace: PoolDefinitionItemService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/pool-definition-items/add-items-to-benefit.md

## Permission Scopes:
Manage benefit programs: SCOPE.BENEFIT_PROGRAMS.MANAGE

## Introduction

Adds up to 100 items to a benefit in a pool definition.


Identify the benefit with `poolDefinitionId` and `benefitKey`, and each item with its `externalId` and `category`. The method creates the corresponding [items](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/items.md), inheriting `providerAppId`, `namespace`, and `itemSetId` from the benefit's configuration in the pool definition. The corresponding pool definition items are then created asynchronously, so new items may take a short time to appear in [Query Pool Definition Items](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/pool-definition-items/query-pool-definition-items.md) results after the call returns.

Add Items to Benefit uses a partial success model. An item that's already assigned to the benefit returns a per-item failure in `results.itemMetadata`, while the other items are added. Check `bulkActionMetadata` for aggregate counts and `results` for per-item outcomes.

To remove items from a benefit, call [Remove Items from Benefit](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/pool-definition-items/remove-items-from-benefit.md).

---

## REST API

### Schema

```
 Method: addItemsToBenefit
 Description: Adds up to 100 items to a benefit in a pool definition.   Identify the benefit with `poolDefinitionId` and `benefitKey`, and each item with its `externalId` and `category`. The method creates the corresponding [items](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/items.md), inheriting `providerAppId`, `namespace`, and `itemSetId` from the benefit's configuration in the pool definition. The corresponding pool definition items are then created asynchronously, so new items may take a short time to appear in [Query Pool Definition Items](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/pool-definition-items/query-pool-definition-items.md) results after the call returns.  Add Items to Benefit uses a partial success model. An item that's already assigned to the benefit returns a per-item failure in `results.itemMetadata`, while the other items are added. Check `bulkActionMetadata` for aggregate counts and `results` for per-item outcomes.  To remove items from a benefit, call [Remove Items from Benefit](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/pool-definition-items/remove-items-from-benefit.md).
 URL: https://www.wixapis.com/benefit-programs/v1/pool-definition-items/add-items-to-benefit
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  itemReferences, itemReferences.externalId, poolDefinitionId, benefitKey
 Method parameters: 
   param name: benefitKey | type: benefitKey | description: Key of the benefit to add the items to. | required: true | validation: maxLength 64
   param name: itemReferences | type: array<itemReferences> | description: Items to add to the benefit. | required: true | validation: minItems 1, maxItems 100
              - name: externalId | type: string | description: External item GUID assigned by the provider app. | required: true | validation: format GUID
              - name: category | type: string | description: Item category. For example, `classes`, `posts`, or `groups`.  Default: `""`  | validation: maxLength 20
   param name: poolDefinitionId | type: poolDefinitionId | description: GUID of the pool definition that contains the benefit. | required: true | validation: format GUID
 Return type: AddItemsToBenefitResponse
  - name: results | type: array<BulkAddItemResult> | description: Per-item results. `itemMetadata.originalIndex` corresponds to the item's position in the `itemReferences` request array.  
     - name: itemMetadata | type: ItemMetadata | description: Result metadata for the created item, including its original index, success status, and error details on failure.  `itemMetadata.id` is the GUID of the created [item](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/items.md), not of a pool definition item. Pool definition items are created asynchronously, so their GUIDs aren't returned.  
        - name: id | type: string | description: Item GUID. Should always be available, unless it's impossible (for example, when failing to create an item).  | validation: format GUID
        - name: originalIndex | type: integer | description: Index of the item within the request array. Allows for correlation between request and response items.  
        - name: success | type: boolean | description: Whether the requested action was successful for this item. When `false`, the `error` field is populated.  
        - name: error | type: ApplicationError | description: Details about the error in case of failure.  
           - name: code | type: string | description: Error code.  
           - name: description | type: string | description: Description of the error.  
           - name: data | type: object | description: Data related to the error.  
  - name: bulkActionMetadata | type: BulkActionMetadata | description: Bulk action metadata, including the number of successes and failures.  
     - name: totalSuccesses | type: integer | description: Number of items that were successfully processed.  
     - name: totalFailures | type: integer | description: Number of items that couldn't be processed.  
     - name: undetailedFailures | type: integer | description: Number of failures without details because detailed failure threshold was exceeded.  

 Possible Errors:
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: POOL_DEFINITION_BENEFIT_NOT_FOUND | Description: Couldn't find the pool definition benefit. Make sure the pool definition with the specified `poolDefinitionId` has a benefit with the specified `benefitKey`.


```

### Examples

### Add classes to a benefit
Adds 2 classes to a benefit in a pool definition.

```curl
curl -X POST \
'https://www.wixapis.com/benefit-programs/v1/pool-definition-items/add-items-to-benefit' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "itemReferences": [
    {
      "externalId": "7f3e9b21-4c8a-4d6e-b5f2-9a1c3e7d8b40",
      "category": "classes"
    },
    {
      "externalId": "3b6d1e8f-5a2c-4f7b-9e4d-8c1a2f6b3e95",
      "category": "classes"
    }
  ],
  "poolDefinitionId": "76bdb96b-9860-4fb6-a5b8-faf41ebdb26a",
  "benefitKey": "yoga-class"
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.benefitPrograms.poolDefinitionItems.addItemsToBenefit(itemReferences, options)
 Description: Adds up to 100 items to a benefit in a pool definition.   Identify the benefit with `poolDefinitionId` and `benefitKey`, and each item with its `externalId` and `category`. The method creates the corresponding [items](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/items.md), inheriting `providerAppId`, `namespace`, and `itemSetId` from the benefit's configuration in the pool definition. The corresponding pool definition items are then created asynchronously, so new items may take a short time to appear in [Query Pool Definition Items](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/pool-definition-items/query-pool-definition-items.md) results after the call returns.  Add Items to Benefit uses a partial success model. An item that's already assigned to the benefit returns a per-item failure in `results.itemMetadata`, while the other items are added. Check `bulkActionMetadata` for aggregate counts and `results` for per-item outcomes.  To remove items from a benefit, call [Remove Items from Benefit](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/pool-definition-items/remove-items-from-benefit.md).
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  itemReferences, itemReferences.externalId, options.poolDefinitionId, options.benefitKey, options
 Method parameters: 
   param name: itemReferences | type: array<ItemReference> | description: Items to add to the benefit. | required: true | validation: minItems 1, maxItems 100
              - name: externalId | type: string | description: External item GUID assigned by the provider app. | required: true | validation: format GUID
              - name: category | type: string | description: Item category. For example, `classes`, `posts`, or `groups`.  Default: `""`  | validation: maxLength 20
   param name: options | type: AddItemsToBenefitOptions  none | required: true 
        - name: poolDefinitionId | type: string | description: GUID of the pool definition that contains the benefit. | required: true | validation: format GUID
        - name: benefitKey | type: string | description: Key of the benefit to add the items to. | required: true | validation: maxLength 64
 Return type: PROMISE<AddItemsToBenefitResponse>
  - name: results | type: array<BulkAddItemResult> | description: Per-item results. `itemMetadata.originalIndex` corresponds to the item's position in the `itemReferences` request array.  
     - name: itemMetadata | type: ItemMetadata | description: Result metadata for the created item, including its original index, success status, and error details on failure.  `itemMetadata.id` is the GUID of the created [item](https://dev.wix.com/docs/api-reference/business-solutions/benefit-programs/items.md), not of a pool definition item. Pool definition items are created asynchronously, so their GUIDs aren't returned.  
        - name: _id | type: string | description: Item GUID. Should always be available, unless it's impossible (for example, when failing to create an item).  | validation: format GUID
        - name: originalIndex | type: integer | description: Index of the item within the request array. Allows for correlation between request and response items.  
        - name: success | type: boolean | description: Whether the requested action was successful for this item. When `false`, the `error` field is populated.  
        - name: error | type: ApplicationError | description: Details about the error in case of failure.  
           - name: code | type: string | description: Error code.  
           - name: description | type: string | description: Description of the error.  
           - name: data | type: object | description: Data related to the error.  
  - name: bulkActionMetadata | type: BulkActionMetadata | description: Bulk action metadata, including the number of successes and failures.  
     - name: totalSuccesses | type: integer | description: Number of items that were successfully processed.  
     - name: totalFailures | type: integer | description: Number of items that couldn't be processed.  
     - name: undetailedFailures | type: integer | description: Number of failures without details because detailed failure threshold was exceeded.  

 Possible Errors:
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: POOL_DEFINITION_BENEFIT_NOT_FOUND | Description: Couldn't find the pool definition benefit. Make sure the pool definition with the specified `poolDefinitionId` has a benefit with the specified `benefitKey`.


```

### Examples

### Add classes to a benefit
Adds 2 classes to a benefit in a pool definition.

```javascript
import { poolDefinitionItems } from "@wix/benefit-programs";

async function addItemsToBenefit() {
  const response = await poolDefinitionItems.addItemsToBenefit(
    [
      {
        externalId: "7f3e9b21-4c8a-4d6e-b5f2-9a1c3e7d8b40",
        category: "classes",
      },
      {
        externalId: "3b6d1e8f-5a2c-4f7b-9e4d-8c1a2f6b3e95",
        category: "classes",
      },
    ],
    {
      poolDefinitionId: "76bdb96b-9860-4fb6-a5b8-faf41ebdb26a",
      benefitKey: "yoga-class",
    },
  );
}

/* Promise resolves to:
 * {
 *   "results": [
 *     {
 *       "itemMetadata": {
 *         "_id": "0afb61fe-2f24-46dd-babc-3c0b1e037902",
 *         "originalIndex": 0,
 *         "success": true
 *       }
 *     },
 *     {
 *       "itemMetadata": {
 *         "_id": "c5e2a7d9-4b1f-4e6a-8d3c-9f7b2a1e5d84",
 *         "originalIndex": 1,
 *         "success": true
 *       }
 *     }
 *   ],
 *   "bulkActionMetadata": {
 *     "totalSuccesses": 2,
 *     "totalFailures": 0,
 *     "undetailedFailures": 0
 *   }
 * }
 */

```

### addItemsToBenefit (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { poolDefinitionItems } from '@wix/benefit-programs';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { poolDefinitionItems },
  // Include the auth strategy and host as relevant
});


async function addItemsToBenefit(itemReferences,options) {
  const response = await myWixClient.poolDefinitionItems.addItemsToBenefit(itemReferences,options);
};
```

---