Prestashop has an internal webservice which allows accessing a store from a remote application. Since the service is based on REST technology, this allows the remote applications to be cross-platform and use CRUD queries.
To start using the webservice you need to enable it first. To switch on the service go to Advanced Parameters -> Webservice:
Enable Active mode CGI for PHP if your server uses PHP not as an Apache module.
Next you need to create an Access Key, which you will have to specify when connecting the webservice to Prestashop. Each key gives access only to certain resources of the store. To generate a key go to Advanced Parameters -> Webservice -> Add New.
You will need to specify the key code, its description, status, configure access to the necessary system resources. You can also specify which CRUD requests will be available for each Prestashop resource (View, Mоdufy, Add, Delete, Fast view ). There is also an option to configure a multishop-association:
The following address pattern gives access to the webservice:
This address authirizes the access to the webservice. Then you can use the URL without the access key:
After querying this URL Prestashop will return an XML file with the list of all resources and all permitted CRUD operations for that resource for the specified Access Key.
To get a list of entities for a particular resource you need to query the following address:
For example, if we need to get a list of all customers we need to send the following get-request:
An example of the response:
To obtain a specific entity by ID use the following query:
For example, this is how to obtain information about a customer with ID = 1.
An example of the response:
The requests will work only if you allow the method GET for the resource Customer.
As shown in the table below, CRUD requests correspond to the type of an HTTP-request:
Comparison table of CRUD-requests and types of SQL queries.
|HTTP / REST
To delete a resource entity use the following request pattern:
An example of removing a customer by ID:
To update customer data you need to get an XML from the following address:
Then change the necessary fields and send the XML back using the following request:
To create a new customer first get an XML using this request:
Fill out the XML with necessary data and send it back using the query:
All requests have a similar structure for each Prestashop resource. The main thing is that there should be access allowed to that resource and to CRUD operations for the key being used.
There is a ready-to-use PHP library written by Prestashop developers to work with the webservice. The library is available on Github. To use this library you should install cURL on the server with a remote application.
You can find examples of usage here.