PrestaShop Documentation, PrestaShop Tutorials

Prestashop how to configure and use web services (API)

Configuring and using the PrestaShop Webservice (API) lets you connect your store with external apps (mobile apps, ERP, CRM, automation scripts, etc.). Here’s a clear, practical guide.


🔧 1. Enable Webservice in PrestaShop

  1. Go to Advanced Parameters → Webservice
  2. Turn ON:
    • Enable PrestaShop Webservice
  3. Save

👉 If you’re on Apache, make sure:

  • mod_rewrite is enabled
  • .htaccess is working (Regenerate from SEO & URLs if needed)

🔑 2. Create API Key

  1. Go to Advanced Parameters → Webservice
  2. Click “Add new webservice key”
  3. Fill:
    • Key: Click Generate
    • Description: e.g., “Mobile App API”
    • Status: Enable

🔐 3. Set Permissions

You’ll see a list of resources like:

  • products
  • categories
  • customers
  • orders
  • carts

Set permissions:

  • GET → Read
  • POST → Create
  • PUT → Update
  • DELETE → Remove

👉 Example:

  • For product sync: enable GET, POST, PUT on products

🌐 4. API Endpoint Structure

Your API base URL:

https://yourdomain.com/api/

Example endpoints:

  • Products:
https://yourdomain.com/api/products
  • Customers:
https://yourdomain.com/api/customers

🔐 5. Authentication

PrestaShop API uses Basic Auth:

  • Username = API Key
  • Password = (leave empty)

🧪 6. Test API in Browser / Postman

Browser test:

https://API_KEY@yourdomain.com/api/products

Postman setup:

  • Method: GET
  • URL: https://yourdomain.com/api/products
  • Auth:
    • Type: Basic Auth
    • Username: API KEY
    • Password: blank

📦 7. Example API Requests

✅ Get all products

GET /api/products

✅ Get specific product

GET /api/products/1

✅ Create product (POST)

<prestashop>
  <product>
    <name>
      <language id="1">Test Product</language>
    </name>
    <price>100</price>
    <active>1</active>
  </product>
</prestashop>

✅ Update product

PUT /api/products/1

✅ Delete product

DELETE /api/products/1

🐘 8. PHP Example (cURL)

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

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $apiKey.':');

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

echo $response;

⚠️ 9. Common Issues & Fixes

❌ 401 Unauthorized

  • Wrong API key
  • Permissions not set

❌ 404 Not Found

  • Pretty URLs issue → regenerate .htaccess

❌ 500 Server Error

  • Enable debug mode in PrestaShop
  • Check server logs

❌ Empty response

  • Resource permissions missing

🔒 10. Security Best Practices

  • Never expose API key publicly
  • Restrict IP access (if possible)
  • Use HTTPS only
  • Create separate keys per integration

🚀 11. Use Cases

  • Mobile app integration
  • ERP / accounting sync
  • Inventory automation
  • Order processing system
  • Marketplace integration

👍 Pro Tips (Advanced)

  • Use filters:
/api/products?filter[price]=[100,200]
  • Use display fields:
/api/products?display=[id,name,price]
  • Use output format JSON (newer versions):
/api/products?output_format=JSON

 

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 →