> 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 # DecrementInventory # Package: catalogV1 # Namespace: InventoryWriteApi # Method link: https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/inventory/decrement-inventory.md ## Permission Scopes: Manage Products: SCOPE.DC-STORES.MANAGE-PRODUCTS ## Introduction Subtracts a set number of items from inventory. --- ## REST API ### Schema ``` Method: decrementInventory Description: Subtracts a set number of items from inventory. URL: https://www.wixapis.com/stores/v2/inventoryItems/decrement Method: POST Method parameters: param name: decrementData | type: array - ONE-OF: - name: inventoryId | type: string | description: Inventory item GUID. - name: productId | type: string | description: Product GUID. - name: variantId | type: string | description: Variant GUID. - name: decrementBy | type: integer | description: Number to decrement inventory by. - name: preorderRequest | type: boolean | description: Whether the request to decrement the item's inventory was made as part of a purchase that includes preorder items. If true and the item is available for preorder, we allow negative inventory. If false and the item is not available for preorder, we allow regular buy flow (no negative inventory). Return type: DecrementInventoryResponse EMPTY-OBJECT {} ``` ### Examples ### DecrementInventory ```curl ~~~cURL curl -X POST https://www.wixapis.com/stores/v2/inventoryItems/decrement \ -H 'Content-Type: application/json' \ -H 'Authorization: ' \ --data-binary ' { "decrementData": [ { "productId": "f007074f-d7a8-a68b-e6c1-7d7c3de021ff", "variantId": "00000000-0000-0001-0005-9ccb19c4e6f0", "decrementBy": 2 } ] }' ~~~ ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.catalogV1.InventoryWriteApi.decrementInventory(decrementData) Description: Subtracts a set number of items from inventory. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: decrementData Method parameters: param name: decrementData | type: array | required: true - ONE-OF: - name: inventoryId | type: string | description: Inventory item GUID. - name: productId | type: string | description: Product GUID. - name: variantId | type: string | description: Variant GUID. - name: decrementBy | type: integer | description: Number to decrement inventory by. - name: preorderRequest | type: boolean | description: Whether the request to decrement the item's inventory was made as part of a purchase that includes preorder items. If true and the item is available for preorder, we allow negative inventory. If false and the item is not available for preorder, we allow regular buy flow (no negative inventory). Return type: PROMISE EMPTY-OBJECT {} ``` ### Examples ### Decrement the inventory of a product's first variant ```javascript /************************************** * Backend code - inventory.web.js/ts * **************************************/ import { Permissions, webMethod } from '@wix/web-methods'; import { inventory } from '@wix/stores'; export const decrementInventory = webMethod(Permissions.Anyone, (decrementData) => { return inventory.decrementInventory(decrementData); }); /************** * Page code * **************/ import { decrementInventory } from 'backend/inventory.web'; async function decrementHandler() { const productId = "3fb6a3c8-988b-8755-04bd-ks75ae0b18ea" let variants = await getProductVariants(productId); decrementInventory( [{ variantId: variants[0]._id, productId: productId, decrementBy: 1 }]) .then(() => { console.log("Inventory decremented successfully") }) .catch(error => { // Inventory decrement failed console.error(error); }) } ``` ### Decrement inventory Decrease inventory quantity for a product variant ```javascript import { inventory } from "@wix/stores"; const decrementData = [ { productId: "c43d36c5-c35a-91ec-1c33-d28efc70d5a6", variantId: "00000000-0000-0000-0000-000000000000", decrementBy: 2 } ]; async function decrementInventory() { const response = await inventory.decrementInventory(decrementData); return response; } const result = await inventory.decrementInventory(decrementData); ``` ### decrementInventory (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/stores'; // 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 decrementInventory(decrementData) { const response = await myWixClient.inventory.decrementInventory(decrementData); }; ``` ---