We used cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. What For?

« Back to Blogs

How to Access PrestaShop Web Services

PrestaShop web services

 

Prestashop allows access to shop’s database for external applications through web services in form of a CRUD API. You can access web services of prestashop using webservice key, prestashop allow you to create multiple web service key with different prestashop resource access permission.

Generate Prestashop Webservice key

  • Go into your Prestashop Back Office and click on the ADVANCED PARAMETERS ? Webservice

  • Click on Add new webservice key

 

1.png

 

  • Click the Generate button to generate web service authentication key.

  • You can also create your own key but it must be 32 characters long.

  • Using a generated key prevents Unauthorized user from guessing your key.

 

5.png

 

  • web service key provides a way to authorised users to access the web service.

    • Key description is not public, but you can use it for uniquely identified your key.

  • Status use for grant access to your data from a certain key temporarily.

  • Permissions is very important part which enables you to assign rights for each resource to make available for this key.

  • Make sure following options must be yes

    • Enable PrestaShop webservice

    • Enable CGI mode for PHP

 

6.png

 

Access prestashop web service in browser

  • Authorize the access to the webservice using

    • http://Webservice-key@Prestashop-URL/api/

  • After Authorise you can use the URL without the access key using

    • http://Prestashop-URL/api/

  • On accessing http://Prestashop-URL/api/ Prestashop return an XML file with the list of all resources and all permitted CRUD operations for that resource for the specified Access Key.


 

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

<api shop_name="test prestashop">

<addresses xlink:href="http://shop.prestashop.com/api/addresses" get="true" put="true" post="true" delete="true" head="true">

<description xlink:href="http://shop.prestashop.com/api/addresses" get="true" put="true" post="true" delete="true" head="true">The Customer, Manufacturer and Customer addresses</description>

<schema xlink:href="http://shop.prestashop.com/api/addresses?schema=blank" type="blank"/>

<schema xlink:href="http://shop.prestashop.com/api/addresses?schema=synopsis" type="synopsis"/>

</addresses>

<carriers xlink:href="http://shop.prestashop.com/api/carriers" get="true" put="true" post="true" delete="true" head="true">

<description xlink:href="http://shop.prestashop.com/api/carriers" get="true" put="true" post="true" delete="true" head="true">The Carriers</description>

<schema xlink:href="http://shop.prestashop.com/api/carriers?schema=blank" type="blank"/>

<schema xlink:href="http://shop.prestashop.com/api/carriers?schema=synopsis" type="synopsis"/>

</carriers>

<cart_rules xlink:href="http://shop.prestashop.com/api/cart_rules" get="true" put="true" post="true" delete="true" head="true">

<description xlink:href="http://shop.prestashop.com/api/cart_rules" get="true" put="true" post="true" delete="true" head="true">Cart rules management</description>

<schema xlink:href="http://shop.prestashop.com/api/cart_rules?schema=blank" type="blank"/>

<schema xlink:href="http://shop.prestashop.com/api/cart_rules?schema=synopsis" type="synopsis"/>

</cart_rules>

<carts xlink:href="http://shop.prestashop.com/api/carts" get="true" put="true" post="true" delete="true" head="true">

<description xlink:href="http://shop.prestashop.com/api/carts" get="true" put="true" post="true" delete="true" head="true">Customer's carts</description>

<schema xlink:href="http://shop.prestashop.com/api/carts?schema=blank" type="blank"/>

<schema xlink:href="http://shop.prestashop.com/api/carts?schema=synopsis" type="synopsis"/>

</carts>

<categories xlink:href="http://shop.prestashop.com/api/categories" get="true" put="true" post="true" delete="true" head="true">

<description xlink:href="http://shop.prestashop.com/api/categories" get="true" put="true" post="true" delete="true" head="true">The product categories</description>

<schema xlink:href="http://shop.prestashop.com/api/categories?schema=blank" type="blank"/>

<schema xlink:href="http://shop.prestashop.com/api/categories?schema=synopsis" type="synopsis"/>

</categories>

 

  • If get, put, post, and delete attributes have true value, It means that you have all permission of that resource.

  • Using XLink, you will be able to access various resources. XLink associates an XML file to another XML file using link.

  • Each element contains a description of the resource, and two schemas:

    • blank is use to create a new item.

      • http://shop.prestashop.com/api/categories?schema=blank

    • synopsis is just like the blank one but with a detailed description of what type of data is expected in each element.

      • http://shop.prestashop.com/api/categories?schema=synopsis

 

<categories xlink:href="http://shop.prestashop.com/api/categories" get="true" put="true" post="true" delete="true" head="true">

<description xlink:href="http://shop.prestashop.com/api/categories" get="true" put="true" post="true" delete="true" head="true">The product categories</description>

<schema xlink:href="http://shop.prestashop.com/api/categories?schema=blank" type="blank"/>

<schema xlink:href="http://shop.prestashop.com/api/categories?schema=synopsis" type="synopsis"/>

</categories>

  • To get a list of resource category use xlink

    • http://shop.prestashop.com/api/categories

 

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

   <categories>

       <category id="1" xlink:href="http://shop.prestashop.com/api/categories/1"/>

       <category id="2" xlink:href="http://shop.prestashop.com/api/categories/2"/>

   </categories>

</prestashop>

  • To get a details of category 1 use xlink

    • http://shop.prestashop.com/api/categories/1

Adding and editing a resource

  • To add a category or any other resource

    • GET the XML blank data of resource

      • Example : http://prestashop-url/api/categories?schema=blank

    • Fill it with new data, and POST the whole XML file to the /api/categories/ URL again.

    • PrestaShop will take care of adding everything in the database.

    • It will return an XML file indicating that the operation has been successful, along with the ID of the newly created customer.

  • To edit an existing resource

    • GET the full XML file of resource you want to change (/api/categories/2), edit its content as needed, then PUT the whole XML file back to the same URL again.
contact-us Request a callback WhatsApp