Site icon PrestaShop | Magento | CRM Modules

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:


πŸ”‘ 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:

Set permissions:

πŸ‘‰ Example:


🌐 4. API Endpoint Structure

Your API base URL:

https://yourdomain.com/api/

Example endpoints:

https://yourdomain.com/api/products
https://yourdomain.com/api/customers

πŸ” 5. Authentication

PrestaShop API uses Basic Auth:


πŸ§ͺ 6. Test API in Browser / Postman

Browser test:

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

Postman setup:


πŸ“¦ 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

❌ 404 Not Found

❌ 500 Server Error

❌ Empty response


πŸ”’ 10. Security Best Practices


πŸš€ 11. Use Cases


πŸ‘ Pro Tips (Advanced)

/api/products?filter[price]=[100,200]
/api/products?display=[id,name,price]
/api/products?output_format=JSON

Β 

Exit mobile version