TanvirSharif Posted March 10, 2023 Share Posted March 10, 2023 Here is my API url of a PUT method:https://{{api_key}}@prestashop.test/api/combinations/10 This is by body data in XML format: <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <combination> <id><![CDATA[10]]></id> <id_product xlink:href="https://prestashop.test/api/products/2"><![CDATA[2]]></id_product> <location><![CDATA[]]></location> <ean13><![CDATA[]]></ean13> <isbn><![CDATA[]]></isbn> <upc><![CDATA[]]></upc> <mpn><![CDATA[]]></mpn> <quantity>200</quantity> <reference><![CDATA[demo_3]]></reference> <supplier_reference><![CDATA[demo_3_63]]></supplier_reference> <wholesale_price><![CDATA[0.000000]]></wholesale_price> <price><![CDATA[0.000000]]></price> <ecotax><![CDATA[0.000000]]></ecotax> <weight><![CDATA[0.000000]]></weight> <unit_price_impact><![CDATA[0.000000]]></unit_price_impact> <minimal_quantity><![CDATA[1]]></minimal_quantity> <low_stock_threshold><![CDATA[]]></low_stock_threshold> <low_stock_alert><![CDATA[0]]></low_stock_alert> <default_on><![CDATA[]]></default_on> <available_date><![CDATA[0000-00-00]]></available_date> <associations> <product_option_values nodeType="product_option_value" api="product_option_values"> <product_option_value xlink:href="https://prestashop.test/api/product_option_values/2"> <id><![CDATA[2]]></id> </product_option_value> </product_option_values> <images nodeType="image" api="images/products"/> </associations> </combination> </prestashop> It gives me 200 ok but the quantity remains same as before. not updated to 200 as I need to set it. Can anyone tell me why and what I should do. Link to comment Share on other sites More sharing options...
innovacy Posted March 16, 2023 Share Posted March 16, 2023 (edited) In newer PrestaShop versions, the stock of a combination is managed by the stock_available entity. The "quantity" field is not being used and has been superseded. To update the stock of a combination using the PrestaShop Web Service API, follow these steps: Retrieve the id_stock_available: To get the id_stock_available for a specific combination, you can use the GET method with the /combinations resource: GET https://yourshop.com/api/stock_availables?display=[id]&filter[id_product]=YOUR_PRODUCT_ID&filter[id_product_attribute]=YOUR_COMBINATION_ID Replace yourshop.com with your domain, YOUR_PRODUCT_ID with the specific product ID you want to update, and YOUR_COMBINATION_ID with the specific combination ID (id_product_attribute). Update the stock available quantity: Now that you have the id_stock_available (returned as id), you can update the stock quantity using the PUT method with the /stock_availables resource: PUT https://yourshop.com/api/stock_availables/STOCK_AVAILABLE_ID Replace yourshop.com with your domain, and STOCK_AVAILABLE_ID with the id_stock_available you obtained in the previous step. In the XML body of your PUT request, set the new stock quantity: <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <stock_available> <id><![CDATA[STOCK_AVAILABLE_ID]]></id> <id_product><![CDATA[YOUR_PRODUCT_ID]]></id_product> <id_product_attribute><![CDATA[YOUR_COMBINATION_ID]]></id_product_attribute> <quantity><![CDATA[NEW_QUANTITY]]></quantity> <depends_on_stock><![CDATA[0]]></depends_on_stock> <out_of_stock><![CDATA[2]]></out_of_stock> </stock_available> </prestashop> Replace STOCK_AVAILABLE_ID with the id_stock_available, YOUR_PRODUCT_ID with the specific product ID you want to update, YOUR_COMBINATION_ID with the specific combination ID (id_product_attribute), and NEW_QUANTITY with the desired stock quantity. In newer versions of PrestaShop, you can utilize the PATCH method to update only the id and quantity, allowing you to bypass the need to include other required fields. That's the method we use to efficiently perform tens of thousands of stock updates on a daily basis. Please refer to the API reference to ensure that all my provided examples are accurate, as I haven't tested them personally, but simply sharing them based on my memory of the PrestaShop API. Edited March 17, 2023 by innovacy (see edit history) 1 Link to comment Share on other sites More sharing options...
TanvirSharif Posted March 17, 2023 Author Share Posted March 17, 2023 @innovacy Thank you for your reply. And it works! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now