Site icon PrestaShop | General Knowledge

PrestaShop Update product using API

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:

⚠️ 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

ErrorCauseFix
500Missing XML fieldsUse GET β†’ PUT flow
401Auth issueCheck API key
403PermissionEnable PUT for products
406Wrong lang IDUse correct language ID
Update succeeds but not visibleCacheClear 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


Β 

Exit mobile version