PrestaShop - Update Stock
Description
Section titled “Description”This module updates the stock quantity of a product or combination (variant) in a PrestaShop store through its REST API. The execution flow is:
- Gets the credentials (apiKey and urlBase) from the PrestaShop store.
- 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.
- First searches in combinations (
- Gets the
stock_availablerecord for the product (or combination) by querying the API with filters byid_productandid_product_attribute. - Downloads the current stock XML, modifies the quantity, and sends it back via PUT.
- Returns confirmation with the product, combination, stock IDs, and updated quantity.
Supports both simple products and products with combinations (variants by size, color, etc.).
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| credentials_id | credentials | Yes | PrestaShop API credentials (apiKey and urlBase). |
| is_combination | boolean | No | Indicates if the product is a combination/variant. Default: true. |
| reference | text | No | Product or combination reference. Used to automatically search for the product_id. |
| product_id | text | No | PrestaShop product ID. Required if reference is not provided. |
| product_attribute_id | text | No | Combination/variant ID. Required for combinations if reference is not provided. |
| stock_quantity | number | Yes | New stock quantity to set. |
Credentials
Section titled “Credentials”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).
Output
Section titled “Output”{ "nextModule": "next-node", "data": { "success": true, "product_id": 42, "product_attribute_id": 15, "is_combination": true, "stockId": 108, "updated_quantity": 25, "response": "<xml>...</xml>" }}Usage Example
Section titled “Usage Example”Basic case - By reference
Section titled “Basic case - By reference”{ "credentials_id": "credencial-prestashop", "reference": "REF-CAMISETA-L-AZUL", "stock_quantity": 50, "is_combination": true}Basic case - By IDs
Section titled “Basic case - By IDs”{ "credentials_id": "credencial-prestashop", "product_id": "42", "product_attribute_id": "15", "stock_quantity": 25, "is_combination": true}API Used
Section titled “API Used”- 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, andproduct_option_values. - Reference search first tries combinations and then simple products.
- For simple products (without combinations), use
is_combination: falseor leaveproduct_attribute_idempty. - 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.
Related Nodes
Section titled “Related Nodes”- Other ecommerce modules (PrestaShop, WooCommerce)
- validate (Data Validator - to validate data before updating)