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 →