Prestashop Web Services

Prestashop Web Services

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:

1

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.

2

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:

3

The following address pattern gives access to the webservice:

http://access_key@url_to_prestashop/api/

This address authirizes the access to the webservice. Then you can use the URL without the access key:

http://url_to_prestashop/api/

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.

4

To get a list of entities for a particular resource you need to query the following address:

GET http://url_to_prestashop/api/resourse

For example, if we need to get a list of all customers we need to send the following get-request:

GET http://url_to_prestashop/api/customers

An example of the response:

5

To obtain a specific entity by ID use the following query:

GET http://url_to_prestashop/api/resourse/1

For example, this is how to obtain information about a customer with ID = 1.

GET http://url_to_prestashop/api/customers/1

An example of the response:

6

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 CRUD SQL
DELETE Delete DELETE
GET Retrieve SELECT
POST Create INSERT
PUT Update UPDATE

To delete a resource entity use the following request pattern:

DELETE http://url_to_prestashop/api/resourse/id

An example of removing a customer by ID:

DELETE http://url_to_prestashop/api/customers/1

To update customer data you need to get an XML from the following address:

GET http://url_to_prestashop/api/customers/1?schema=synopsis

Then change the necessary fields and send the XML back using the following request:

PUT http://url_to_prestashop/api/customers/1?schema=synopsis

To create a new customer first get an XML using this request:

GET http://url_to_prestashop/api/customers?schema=blank

Fill out the XML with necessary data and send it back using the query:

POST http://url_to_prestashop/api/customers?schema=blank

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.



22 comments

  1. Hi, Thanks for this post!
    I have a problem with web service in prestashop in order to update a product. I am using javascript to retrieve information and it works fine. I can insert new product with web service using javascript but I cannot update product. When I try it and I get the error 400 bad request doing PUT request. I’ll explain it:

    To insert: GET xxxxxxxx@www.shop.com/api/products?schema=blank. With this XML I fill data and POST the XML and xxxxxxxx@www.shop.com/api/products?schema=blank , and workd fine.

    To update: (obviously product 1250 is yet in database) GET xxxxxxxx@www.shop.com/api/products/1250?schema=synopsis. With this XML I change one field value and PUT the XML and xxxxxxxx@www.shop.com/api/products/1250?schema=synopsis and it doesn’t works. I get 400 bad request. Can you help me, please?. Thanks

  2. Juan,

    Try to activate ‘display_errors’ function in defines.inc.php, look what error you will get doing put request, and send it to us.

  3. Hi, I am trying to create order using prestashop 1.5.6.1 webservice. I could add customer, address, and cart but while creating order, it’s throwing error orderDetail->product_name is empty. Product is also not shown in cart and order. after adding order all amount values are shown zero. please suggest any workaround

  4. Hi,
    I am working on the 1.6 version and I have tried to enable REST webservice from localhost.
    when I visit this link
    http://localhost/myshop/api/
    I can’t get any xml .. the only page that I see is the 404 http_error.
    Have you any idea about that ?
    thanks in advance..

  5. Hello,

    Nice article. You know how fields are required if I want create new product via REST service?

    Thanks,

  6. Xabi,

    You can find all the mandatory fields in the classes/Product.php you need to find $definition attribute there. All fields are listed there. If the field has a key “required” it means that the field is required.

  7. Great article, I however get an error when I try to view a specific order. Below is the error I get. When I turn debugging on it works fine. As soon as I turn it off the error returns. Any idea what it might be ?

    Internal error. To see this error please display the PHP errors.

  8. Hello:

    I have a prestashop running as a catalog, my problem is that I want to update the products stock via webservice. The webservice is provided by the supplier but I don’t know how to connect the WSDL from the supplier to my prestashop.

    Can you help me?

  9. hi denis,

    this is helpful and clear.

    1. i am just starting with prestashop and was wondering whether prestashop allows additional resources to be registered with the rest engine, so you can use it to access other resources than the ones in the default list. ( and of course in order to do so, what additional coding lies ahead )

    2. i would also be interested in creating json (bson) web services and use client side javascript to render stuff. it seems to me that performance wise this could be something. what are your thoughts on this?

  10. Great post, more easy than the Prestashop’s docs.

    Did you know how to erase products images? I’m trying it but I don’t have permission to delete it (and the permissions are activated on backoffice for my key) if y access to http://myshop.com/api/images with a browser I can read:

    I’m working in a little script to remove duplicate images comparing all images of a product.

  11. Thank you so much for the blog. It was more than useful for me.
    :)
    Short as well as sweet one.

  12. Hi,
    Can you please give us sample xml request to be send with the required parameters especially for creation and updation of products and orders?

  13. Hi, this is a nice blog i have completed my application with prestashop restfull service i just need to place an order. with shiping and discount but it is giving error each time i place an order can u help me to place an order with rest full service.

  14. how to get the jsonformat data from webservice insted of xml format
    ?outputformat=json in url not working show a blank page

  15. Hi 2 all and thanks for the post. I’m trying to developing a new model to sync both prestashop sites using webservices but first step to do that is enable automatically webservices when my custom module is installed.

    Is there a way to do that?

  16. hi guys, hello from portugal :)
    i’m newer at prestashop, i’m trying to use web services from prestashop to comunicate with other api (PHC), but for now i’m trying with standard prestashop web service (backoffice) and i’m testing with chrome extension (POSTMAN)…and the results are:

    GET and DELETE are ok…
    But POST and PUT :( not…

    I have read and read a lot of information (google) but until now i’m not able to find something that works for me.
    Some help please!!!!

    Best regards,
    Rui

Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *