Perfect β updating a product via PrestaShop Webservice API is a bit stricter than creating one, so Iβll walk you through the safe + correct way π
(If you skip steps, PrestaShop throws a 500 π
)
Core Rule (Donβt Skip This)
π UPDATE = GET β MODIFY β PUT
You cannot send partial XML like other APIs.
1οΈβ£ Know the Product ID
Example:
Product ID = 123
Update endpoint:
/api/products/123
2οΈβ£ Get Existing Product XML
This is mandatory.
CURL
curl -X GET "https://yourstore.com/api/products/123" \
-u API_KEY:
This returns full product XML.
3οΈβ£ Modify Only What You Need
Common updates:
- price
- name
- active
- description
- category
- SEO fields
β οΈ Do NOT remove nodes
β οΈ Keep <id>123</id> inside <product>
4οΈβ£ Sample XML β Update Product
<?xml version="1.0" encoding="UTF-8"?>
<prestashop>
<product>
<id>123</id>
<price>1199</price>
<active>1</active>
<name>
<language id="1">Updated Product Name</language>
</name>
<link_rewrite>
<language id="1">updated-product-name</language>
</link_rewrite>
</product>
</prestashop>
5οΈβ£ PUT Request (Update Product)
curl -X PUT "https://yourstore.com/api/products/123" \
-u API_KEY: \
-H "Content-Type: application/xml" \
-d @product-update.xml
β Success β 200 OK
6οΈβ£ PHP Example β Update Product
$apiKey = 'YOUR_API_KEY';
$productId = 123;
$url = "https://yourstore.com/api/products/$productId";
// Step 1: Get product
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => $apiKey . ':'
]);
$xml = curl_exec($ch);
curl_close($ch);
// Step 2: Modify XML
$xmlObj = simplexml_load_string($xml);
$xmlObj->product->price = 1199;
$xmlObj->product->name->language[0] = 'Updated Product Name';
// Step 3: PUT update
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_USERPWD => $apiKey . ':',
CURLOPT_HTTPHEADER => ['Content-Type: application/xml'],
CURLOPT_POSTFIELDS => $xmlObj->asXML()
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
7οΈβ£ Updating Stock (Separate API β)
Price β quantity.
Get stock ID
/api/stock_availables?filter[id_product]=123
Update stock quantity
<prestashop>
<stock_available>
<id>STOCK_ID</id>
<quantity>50</quantity>
</stock_available>
</prestashop>
PUT to:
/api/stock_availables/STOCK_ID
8οΈβ£ Common Errors & Fixes
| Error | Cause | Fix |
|---|---|---|
| 500 | Missing XML fields | Use GET β PUT flow |
| 401 | Auth issue | Check API key |
| 403 | Permission | Enable PUT for products |
| 406 | Wrong lang ID | Use correct language ID |
| Update succeeds but not visible | Cache | Clear PS cache |
9οΈβ£ Best Practices (Battle-tested)
β Always GET before PUT
β Keep product <id>
β Use XML for updates
β Donβt touch manufacturer_name
β Stock updated separately
β Clear cache after bulk updates
Β
