PrestaShop Documentation, PrestaShop Tutorials

PrestaShop Create product via API

Got it — let’s do a real, working “Create Product via PrestaShop API” walkthrough, step by step, no fluff 💪
This is the exact flow pros use.


1️⃣ Requirements (quick check)

  • PrestaShop Webservice enabled
  • API key with POST permission for products
  • HTTPS store URL

Endpoint you’ll POST to:

/api/products

2️⃣ ALWAYS start with schema (very important)

PrestaShop will fail if required fields are missing.

Get blank product schema

Open in browser or via CURL:

curl -X GET "https://yourstore.com/api/products?schema=blank" \
-u API_KEY:

You’ll get a full XML structure.
👉 Edit only required fields, don’t delete nodes.


3️⃣ Minimal Required Fields for Product

These are mandatory (most common):

  • name
  • price
  • id_category_default
  • active
  • link_rewrite
  • associations > categories

Language ID must match your store (usually 1).


4️⃣ Sample XML – Create Product (WORKING)

<?xml version="1.0" encoding="UTF-8"?>
<prestashop>
  <product>
    <active>1</active>
    <price>999</price>
    <id_category_default>2</id_category_default>

    <name>
      <language id="1">API Test Product</language>
    </name>

    <link_rewrite>
      <language id="1">api-test-product</language>
    </link_rewrite>

    <description_short>
      <language id="1">Created via PrestaShop API</language>
    </description_short>

    <associations>
      <categories>
        <category>
          <id>2</id>
        </category>
      </categories>
    </associations>
  </product>
</prestashop>

5️⃣ POST Product via CURL

curl -X POST "https://yourstore.com/api/products" \
-u API_KEY: \
-H "Content-Type: application/xml" \
-d @product.xml

✅ Success response → 201 Created
Response contains product ID 🎉


6️⃣ PHP Example (Create Product)

$apiKey = 'YOUR_API_KEY';
$url = 'https://yourstore.com/api/products';

$xml = <<<XML
<prestashop>
  <product>
    <active>1</active>
    <price>999</price>
    <id_category_default>2</id_category_default>
    <name>
      <language id="1">API Test Product</language>
    </name>
    <link_rewrite>
      <language id="1">api-test-product</language>
    </link_rewrite>
    <associations>
      <categories>
        <category><id>2</id></category>
      </categories>
    </associations>
  </product>
</prestashop>
XML;

$ch = curl_init($url);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_USERPWD => $apiKey . ':',
    CURLOPT_HTTPHEADER => ['Content-Type: application/xml'],
    CURLOPT_POSTFIELDS => $xml
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

7️⃣ Add Stock Quantity (VERY COMMON CONFUSION)

Creating product ≠ stock update ❌
Stock is managed separately.

Get stock ID

GET /api/stock_availables?filter[id_product]=PRODUCT_ID

Update 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 Fix
500 Internal Server Error Missing required XML fields
401 Unauthorized Wrong API key
403 Forbidden Permission not allowed
406 Invalid XML / language ID
Product created but invisible active = 0

9️⃣ Pro Tips (Save Your Time)

✔ Always use schema=blank
✔ Never remove XML nodes blindly
✔ Use correct language ID
✔ Categories are mandatory
✔ Stock handled separately
✔ Use XML for POST/PUT (JSON is risky)


 

About zohaibk

We develop useful addons for #E-Commerce and #CRM software to provide extra features.#PrestaShop,#Magento,#SugarCRM,#Vtiger & #Android #apps
View all posts by zohaibk →