How to use the PrestaShop API

In information technology, a Web Service for the W2C standard is software designed for interoperability between different computers on the same network. PrestaShop has its own Web Service that can be useful for exchanging data between PrestaShop and another software that can be a management system, a web service for synchronization with your Ebay or Amazon store, etc ...

PRESTASHOP API

The first operation to be performed in order to use the WebService is to enable it, to do this we will have to go to: Advanced parameters -> Webservice

Create an API key in PrestaShop

Click on the + to create a new web service

Set the PrestaShop API permissions
  • We click on "Generate!" to create a new key to access the webservice
  • We insert 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 you to activate 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 methods are GET, PUT, POST, DELETE and HEAD. In the example we select all the GET permissions.

Once this is done, click on "SAVE".

Enable the PrestaShop WebService

We just have to activate the PrestaShop WebService now by activating the item "Activate PrestaShop web service", in most cases our server has the CGI mode for PHP, so we also activate the item "Enable CGI mode for PHP" and click on SAVE

Now we can query the PrestaShop web service by retrieving the URL address 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 indicate 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 in question as the User Name, without indicating any password.

Access the PrestaShop API

The call will return the available methods:

PrestaShop API methods

We thus ran various queries by receiving the response in XML format from the WebService, for example we can receive the list of all orders by calling the following url: https://www.demomodule.com/api/orders.

Note: You will not need to pass the key again for subsequent queries.

recall orders with the PrestaaShop API

By calling URL https://www.demomodule.com/api/orders/1 we will have 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 are going to delete the customer with ID number 112.

Author: Loris Modena

SENIOR DEVELOPER

For Ind Loris Modena , owner of Arte e Informatica , he began working in the IT sector in 1989 as a system engineer in charge of the maintenance and installation of IT systems. He started programming for the web in 1997 dealing with CGI programming in PERL and then moving on to programming in PHP and JavaScript. In this period he approaches the Open source world and the management of Linux servers.

Product added to wishlist