Skip to content

PrestaShop - Update Stock

This module updates the stock quantity of a product or combination (variant) in a PrestaShop store through its REST API. The execution flow is:

  1. Gets the credentials (apiKey and urlBase) from the PrestaShop store.
  2. If a reference (reference) is provided and the product ID is not available, it automatically searches the PrestaShop API:
    • First searches in combinations (/api/combinations).
    • If not found, searches in products (/api/products).
    • Verifies it is not a product option (product_option_values) that cannot be updated directly.
  3. Gets the stock_available record for the product (or combination) by querying the API with filters by id_product and id_product_attribute.
  4. Downloads the current stock XML, modifies the quantity, and sends it back via PUT.
  5. Returns confirmation with the product, combination, stock IDs, and updated quantity.

Supports both simple products and products with combinations (variants by size, color, etc.).

ParameterTypeRequiredDescription
credentials_idcredentialsYesPrestaShop API credentials (apiKey and urlBase).
is_combinationbooleanNoIndicates if the product is a combination/variant. Default: true.
referencetextNoProduct or combination reference. Used to automatically search for the product_id.
product_idtextNoPrestaShop product ID. Required if reference is not provided.
product_attribute_idtextNoCombination/variant ID. Required for combinations if reference is not provided.
stock_quantitynumberYesNew stock quantity to set.

A credentials_id with an object containing:

  • apiKey: PrestaShop API Key (generated in Backoffice > Advanced Parameters > Webservice).
  • urlBase: Store base URL (e.g.: https://mystore.com).
{
"nextModule": "next-node",
"data": {
"success": true,
"product_id": 42,
"product_attribute_id": 15,
"is_combination": true,
"stockId": 108,
"updated_quantity": 25,
"response": "<xml>...</xml>"
}
}
{
"credentials_id": "credencial-prestashop",
"reference": "REF-CAMISETA-L-AZUL",
"stock_quantity": 50,
"is_combination": true
}
{
"credentials_id": "credencial-prestashop",
"product_id": "42",
"product_attribute_id": "15",
"stock_quantity": 25,
"is_combination": true
}
  • PrestaShop Webservice API:
    • GET {urlBase}/api/combinations?filter[reference]={ref}&display=[id,id_product] - Search combination by reference.
    • GET {urlBase}/api/products?filter[reference]={ref}&display=[id] - Search product by reference.
    • GET {urlBase}/api/stock_availables?filter[id_product]={id}&display=[id] - Get stock_available.
    • GET {urlBase}/api/stock_availables/{id} - Get current stock XML.
    • PUT {urlBase}/api/stock_availables/{id} - Update stock (XML).
  • Authentication: Basic Auth with apiKey.
  • The PrestaShop API requires the Webservice to be enabled and the key to have permissions on the resources products, combinations, stock_availables, and product_option_values.
  • Reference search first tries combinations and then simple products.
  • For simple products (without combinations), use is_combination: false or leave product_attribute_id empty.
  • Stock is set as an absolute value (not incremental). To increment, you must read the current stock and add before calling the module.
  • XML responses are parsed internally using xml2js.
  • Other ecommerce modules (PrestaShop, WooCommerce)
  • validate (Data Validator - to validate data before updating)