> 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 # DecrementAvailability # Package: catalogs # Namespace: InventorySpi # Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/catalogs/inventory-service-plugin/decrement-availability.md ## Introduction Reduces the available stock quantity for specified items. Use this method when inventory needs to be decremented due to order events such as order placement or payment. The method supports validation to prevent negative inventory levels when `restrictInventoryValue` is set to true. --- ## REST API ### Schema ``` Method: decrementAvailability Description: Reduces the available stock quantity for specified items. Use this method when inventory needs to be decremented due to order events such as order placement or payment. The method supports validation to prevent negative inventory levels when `restrictInventoryValue` is set to true. URL: null Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: items, items.catalogReference, items.catalogReference.catalogItemId, items.catalogReference.appId, items.quantity, items.subscriptionItem, restrictInventoryValue, orderId, reason Method parameters: param name: items | type: array | description: Items for which to decrease their available stock quantity. | required: true - name: catalogReference | type: CatalogReference | description: Catalog reference that uniquely identifies the item. Contains the app GUID and catalog item GUID required to locate the specific item in the catalog. | required: true - name: catalogItemId | type: string | description: GUID of the item within the catalog it belongs to. | required: true - name: appId | type: string | description: GUID of the app providing the catalog. You can get your app's GUID from its page in the [app dashboard](https://dev.wix.com/dc3/my-apps/). For items from Wix catalogs, the following values always apply: + Wix Stores: `"215238eb-22a5-4c36-9e7b-e7c08025e04e"` + Wix Bookings: `"13d21c63-b5ec-5912-8397-c3a5ddb27a97"` + Wix Restaurants: `"9a5d83fd-8570-482e-81ab-cfa88942ee60"` | required: true - name: options | type: object | description: Additional item details in `key:value` pairs. Use this optional field for more specificity with item selection. The values of the `options` field differ depending on which catalog is providing the items. For Wix Stores products, learn more about integrating with [Catalog V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/e-commerce-integration.md) or [Catalog V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/e-commerce-integration.md), depending on [the version the site uses](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-versioning/introduction.md). - name: locationId | type: string | description: Location GUID where the inventory is managed. When not provided, the default location is used for inventory tracking. - name: quantity | type: integer | description: Quantity of the item to increment or decrement. For example, `5` to reduce availability by 5 units or increase availability by 5 units. | required: true - name: subscriptionItem | type: boolean | description: Whether the item is part of a subscription order. Subscription items may be processed differently by inventory systems depending on their recurring nature. | required: true param name: orderId | type: orderId | description: Order GUID associated with this inventory change. | required: true param name: reason | type: Reason | required: true - enum: ORDER_PLACED - Order was placed by a customer. ORDER_PAID - Order was paid for by a customer. ORDER_CANCELED - Order was canceled. ORDER_REFUNDED - Order was refunded. ORDER_EDITED - Order was edited by a merchant. ORDER_REJECTED - Order was rejected. param name: restrictInventoryValue | type: restrictInventoryValue | description: Whether to validate that the availability level doesn't become negative after the decrement. When set to `true`, the operation fails if any item would have negative availability after the decrement. When set to `false`, allows negative inventory levels. | required: true Return type: DecrementAvailabilityResponse EMPTY-OBJECT {} Possible Errors: HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DECREMENT_NOT_POSSIBLE | Description: Cannot decrement availability due to insufficient stock or invalid request parameters. ``` ### Examples ### Decrement inventory by 4 units ```curl curl -X POST https://provider.example.com/v1/decrement \ -H 'user-agent: Wix' \ -H 'accept-encoding: gzip, deflate' \ -H 'content-type: text/plain; charset=utf-8' \ -d '{ "items": [ { "catalogReference": { "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", "catalogItemId": "e35409da-d374-4c4b-b08b-6c703c5b6960" }, "locationId": "2163c198-6c85-4d30-b317-48714f627e4b", "quantity": 4, "subscriptionItem": false } ], "orderId": "a22ebad0-11ef-4a4d-a567-691fa7cb264c", "reason": "ORDER_PAID", "restrictInventoryValue": true }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.catalogs.InventorySpi.decrementAvailability(request, metadata) Description: Reduces the available stock quantity for specified items. Use this method when inventory needs to be decremented due to order events such as order placement or payment. The method supports validation to prevent negative inventory levels when `restrictInventoryValue` is set to true. Method parameters: param name: metadata | type: Context | description: this message is not directly used by any service, it exists to describe the expected parameters that SHOULD be provided to invoked Velo methods as part of open-platform. e.g. SPIs, event-handlers, etc.. NOTE: this context object MUST be provided as the last argument in each Velo method signature. Example: ```typescript export function wixStores_onOrderCanceled({ event, metadata }: OrderCanceledEvent) { ... } ``` - name: requestId | type: string | description: A unique identifier of the request. You may print this GUID to your logs to help with future debugging and easier correlation with Wix's logs. - name: currency | type: string | description: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code. - name: identity | type: IdentificationData | description: An object that describes the identity that triggered this request. - ONE-OF: - name: anonymousVisitorId | type: string | description: GUID of a site visitor that has not logged in to the site. - name: memberId | type: string | description: GUID of a site visitor that has logged in to the site. - name: wixUserId | type: string | description: GUID of a Wix user (site owner, contributor, etc.). - name: appId | type: string | description: GUID of an app. - name: languages | type: array | description: A string representing a language and region in the format of `"xx-XX"`. First 2 letters represent the language code according to ISO 639-1. This is followed by a dash "-", and then a by 2 capital letters representing the region according to ISO 3166-2. For example, `"en-US"`. - name: instanceId | type: string | description: The service provider app's instance GUID. param name: request | type: DecrementAvailabilityRequest - name: items | type: array | description: Items for which to decrease their available stock quantity. - name: catalogReference | type: CatalogReference | description: Catalog reference that uniquely identifies the item. Contains the app GUID and catalog item GUID required to locate the specific item in the catalog. - name: catalogItemId | type: string | description: GUID of the item within the catalog it belongs to. - name: appId | type: string | description: GUID of the app providing the catalog. You can get your app's GUID from its page in the [app dashboard](https://dev.wix.com/dc3/my-apps/). For items from Wix catalogs, the following values always apply: + Wix Stores: `"215238eb-22a5-4c36-9e7b-e7c08025e04e"` + Wix Bookings: `"13d21c63-b5ec-5912-8397-c3a5ddb27a97"` + Wix Restaurants: `"9a5d83fd-8570-482e-81ab-cfa88942ee60"` - name: options | type: object | description: Additional item details in `key:value` pairs. Use this optional field for more specificity with item selection. The values of the `options` field differ depending on which catalog is providing the items. For Wix Stores products, learn more about integrating with [Catalog V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/e-commerce-integration.md) or [Catalog V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/e-commerce-integration.md), depending on [the version the site uses](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-versioning/introduction.md). - name: locationId | type: string | description: Location GUID where the inventory is managed. When not provided, the default location is used for inventory tracking. - name: quantity | type: integer | description: Quantity of the item to increment or decrement. For example, `5` to reduce availability by 5 units or increase availability by 5 units. - name: subscriptionItem | type: boolean | description: Whether the item is part of a subscription order. Subscription items may be processed differently by inventory systems depending on their recurring nature. - name: restrictInventoryValue | type: boolean | description: Whether to validate that the availability level doesn't become negative after the decrement. When set to `true`, the operation fails if any item would have negative availability after the decrement. When set to `false`, allows negative inventory levels. - name: orderId | type: string | description: Order GUID associated with this inventory change. - name: reason | type: Reason | description: Reason for the inventory decrement. - enum: - ORDER_PLACED: Order was placed by a customer. - ORDER_PAID: Order was paid for by a customer. - ORDER_CANCELED: Order was canceled. - ORDER_REFUNDED: Order was refunded. - ORDER_EDITED: Order was edited by a merchant. - ORDER_REJECTED: Order was rejected. Return type: PROMISE EMPTY-OBJECT {} Possible Errors: HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DECREMENT_NOT_POSSIBLE | Description: Cannot decrement availability due to insufficient stock or invalid request parameters. ``` ### Examples ### Basic inventory decrement for order placement Decrements inventory when an order is placed, with stock validation enabled ```javascript import { inventory } from "@wix/ecom/service-plugins"; inventory.provideHandlers({ decrementAvailability: async (payload) => { const { request, metadata } = payload; // Use the `request` and `metadata` received from Wix and // apply custom logic. // Example: Log the decrement operation console.log(`Decrementing inventory for order: ${request.orderId}`); // Example: Add custom validation logic const hasSubscriptionItems = request.items.some(item => item.subscriptionItem); if (hasSubscriptionItems) { console.log('Processing subscription items with special handling'); } // Return your response exactly as documented to integrate with Wix. return { // Empty response indicates successful decrement }; } }); ``` ### decrementAvailability (self-hosted) Self-hosted 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 { inventory } from '@wix/ecom/service-plugins'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { inventory }, // Include the auth strategy and host as relevant }); async function decrementAvailability(request,metadata) { const response = await myWixClient.inventory.decrementAvailability(request,metadata); }; ``` ---