PrestaShop API

In computer science, a Web Service (web service) according to the W3C standard is software designed for interoperability between different processors on the same network. PrestaShop has its own Web Service that can be useful for data exchange between PrestaShop and another software, which could be a management system, a web service for synchronization with your eBay or Amazon store, etc...

THE PRESTASHOP API

The first operation to perform in order to use the WebService is to enable it; to do this, we need to go to: Advanced settings -> Webservice

Create an API key in PrestaShop.

Click on the + to create a new web service

Set the API permissions for PrestaShop.
  • Click on "Generate!" to create a new key to access the web service
  • Enter a description for the key we are creating, to remind us what the web service is for, for example: "GLS synchronization" if the web service is used to connect to the courier.
  • Status allows us to enable or disable the key at any time, let's set it to YES to activate access.
  • Permissions, here we can decide which permissions to enable; the methods are GET, PUT, POST, DELETE, and HEAD. In this example, we select all GET permissions.

Once this is done, click on "SAVE".

Enable the PrestaShop WebService

All that remains is to activate the WebService of PrestaShop by enabling the "Activate PrestaShop web service" option. In most cases, our server has CGI mode for PHP, so we also enable the "Enable CGI mode for PHP" option and click on SAVE.

Now we can query the PrestaShop web service by calling the URL formatted as follows: http://key@domainname.ext/api/ or http://domainname.ext/api/?ws_key=key
Example: https://MNXB51PKR6LGRQWS7CNBSUI3JNBVNYSS@www.demomodule.com/api/ or https://www.demomodule.com/api/?ws_key=MNXB51PKR6LGRQWS7CNBSUI3JNBVNYSS

Note: we can also specify the method, for example &ps_method=GET, or the format, for example for JSON we will add to the URL &output_format=JSON.

If our domain is www.demomodule.com and our key is MNXB51PKR6LGRQWS7CNBSUI3JNBVNYSS, if we do not enter the key in the first call, it will be requested by our browser. In this case, it will be sufficient to indicate the key as the Username, without specifying any password.

Access the PrestaShop APIs

The call will return the available methods:

PrestaShop API Methods

We were able to execute various queries, receiving responses from the WebService in XML format. For example, we can receive the list of all orders by calling the following URL: https://www.demomodule.com/api/orders.

Note: it will not be necessary to pass the key again for subsequent queries.

retrieve orders with the Prestashop API

By calling the URL https://www.demomodule.com/api/orders/1 we will get the details of the order with ID 1.

If we have enabled the DELETE method, we can also delete data, for example: https://www.demomodule.com/api/customers/112/?ws_key=MNXB51PKR6LGRQWS7CNBSUI3JNBVNYSS&ps_method=DELETE

We will delete the customer with ID number 112.

Author: Loris Modena

SENIOR DEVELOPER

Per Ind Loris Modena, owner of Arte e Informatica, started working in the IT sector in 1989 as a system administrator responsible for the maintenance and installation of computer systems. He began programming for the web in 1997, focusing on CGI programming in PERL and later transitioning to programming in PHP and JavaScript. During this time, he became familiar with the Open Source world and the management of Linux servers.

Product added to wishlist