🎉 New Integrations Added to the PrestaShop Mobile App!
prestashop rest api

Easily expose your PrestaShop API endpoints to build front-end applications, headless apps and integrate with platforms. Why PrestaShop Webservices API is not enough?

PrestaShop API for Front Applications and Integrations

Download the demo version of PrestaShop REST API Module. Let's create front-end and headless applications based on PrestaShop.

Trusted for many years..

(since 2019, the first API version)
prestashop
                                 api
                                reviews

How Do I Connect to PrestaShop API?

Once you have installed the REST API module access your API:

http://example.tld/rest/

Let's Call the Bootstrap API

Let's check a sample API to see that your endpoints are working correctly by accessing the bootstrap API at: http://example.tld/rest/bootstrap

The response should look like this:

{
    "success": true,
    "code": 200,
    "psdata": {
        "menuItems":                         […]Array
        "featuredProductsList":              […]Array
        "numberOfFeaturedProd":              10
        "banner":	                     {...}Object
        "slides":	                     […]Array
        "languages":	                     […]Array
        "currencies":	                     […]Array
        "logo_url":	                     "https://example.tld/img/logo.png"
    }
}

Production-ready and Official Supported Version (Full Version - Pro)

The full version is the production ready version of the REST API module that includes:

  • A Complete Documentation to Work with the API and to Build Front-end Apps
  • A Complete Set of Front-end APIs
  • Admin APIs
  • API Caching Mechanism
  • REST Hooks
  • Annotation-based API Routing
  • REST API Protection

Read more about the features in the next sections.

Full Version (v5)

Complete Documentation

The manual documentation is a detailed and a must-have guide for building front-end and headless applications. What is included in the guide?

  • How to fix CORS issues (mostly in CSR)
  • How to create orders
  • How to complete Checkout Steps
  • How to add vouchers
  • How to handle product combinations in product detail page
  • How to add product combinations to cart
  • How to filter products with Faceted Search
  • How to work with Wishlist
  • Multi Language and Multi Currency
  • How to protect APIs
  • and many other subjects..

Download from Official PrestaShop Addons.

New Changes in Version 5

Version 5 introduces new Admin APIs and the new Routing Mechanism in addition to the structural changes.

REST API Caching

API level caching adds performance improvements for rendering Home, PLP and PDP pages. This feature is available in Pro version.

REST API caching applied on a PrestaShop website with 100K products and 200 categories and reduced response time from 5 sec to 300 millisec.

Tested on Native Faceted search module and there is no additional tool on server, the REST API module uses file system as the cache driver.

We also did a stress test using the Jmeter for API version and HTML version of the website. Experiment specifications:

server with 1 CPU core
server with 4 GB Ram
100 concurrent threads (active users)

Result:
API throughput: 530/min
HTML throughput: 385/min

Download Full Report

Annotation-Based API Routing (v5)

Writing controllers in PrestaShop has some rules especially for the front-end controllers. PrestaShop REST API module v5 uses the Symfony Routing component for API routing. The routing mechanism is based on the Annotation technology and it can be used for both admin and front APIs.

This way, we can use arbitrary class names and methods, therefore we are not restricted to a naming and directory conventions and we can define routes next to our classes conveniently.

Example:

/**
* @Route("/rest/get-products", name=”products”)
*/
public function getProducts()
{
// ...
}

Currently, Doctrine Annotation technology support added to route API requests, however when PrestaShop's symfony version gets updated it will be possible to have routing based on the Attributes as well.

Introduction of REST Hooks

The REST Hooks give us the ability to customize Binshopsrest API endpoints from third-party modules. REST Hooks added in version 4.5.0. This feature is available in Pro version.

Why REST Hooks?

Currently, if we want to add some data to the current APIs like, bootstrap or productdetail (any change to binshopsrest API endpoints) we have to edit the API controller files directly. As the binshopsrest module gets updated, it would be painful if we want to update binshopsrest module, and we have to manually adopt the new changes while keeping our custom changes. Therefore, the REST Hooks make it easier to customize the main binshopsrest endpoints from third-party modules.

List of REST Hooks

  • restBootstrap (no param)
  • restLogin (params[customer_id])
  • restRegister (params[customer_id])
  • restAccountInfo (params[customer_id])
  • restProductDetail (params[product_id])
  • restCategory (params[category_id])
  • restCart (params[cart_id])
  • restOrderHistory (no param)
  • restAddressForm (no param)
  • restAddressForm (only for get Address endpoint, param[id_address])

How will the REST Hook data be accessed in API?

In the following sample the restBootstrap hook is used in blockwishlist module. The data will be accessible within the hook_data field.

{
    "success": true,
    "code": 200,
    "psdata": {
        "menuItems":                         [..]Array
        "featuredProductsList":              [..]Array
        "numberOfFeaturedProd":              10
        "banner":	                     {..}Object
        "slides":	                     [..]Array
        "languages":	                     [..]Array
        "currencies":	                     [..]Array
        "logo_url":	                     "https://example.tld/img/logo.png"
        "hook_data": {
                "blockwishlist":             [..]Array
        }
    }
}

REST API Protection

You can protect your front-end and admin APIs through the API keys. You can generate API keys through the BO. This feature is available in Pro version.

REST API for PrestaShop Headless Commerce

This REST API gives you the ability to build Headless applications based on PrestaShop, let's see what is the Headless Commerce and why it matters. Read more here or watch the video.

PrestaShop API Example

You can check the online postman documentation, however here is a sample output for a single product:

{
  "success": true,
  "code": 200,
  "psdata": {
    "id_product": 3,
    "name": "The best is yet to come' Framed poster",
    "available_for_order": "1",
    "show_price": "1",
    "new_products": "1",
    "on_sale_products": "0",
    "quantity": 1500,
    "minimal_quantity": "1",
    "allow_out_of_stock": "0",
    "float_price": 29,
    "price": "$29.00",
    "discount_price": "",
    "discount_percentage": "",
    "images": [
      {
        "src": "https://rest.binshops.com/3-large_default/the-best-is-yet-to-come-framed-poster.jpg"
      }
    ],
    "cover_image": "https://rest.binshops.com/3-large_default/the-best-is-yet-to-come-framed-poster.jpg",
    "combinations": [
      {
        "id_product_attribute": 13,
        "quantity": 900,
        "price": "$29.00",
        "float_price": 29,
        "minimal_quantity": 1,
        "combination_code": "19"
      },
      {
        "id_product_attribute": 14,
        "quantity": 300,
        "price": "$49.00",
        "float_price": 49,
        "minimal_quantity": 1,
        "combination_code": "20"
      },
      {
        "id_product_attribute": 15,
        "quantity": 300,
        "price": "$79.00",
        "float_price": 79,
        "minimal_quantity": 1,
        "combination_code": "21"
      }
    ],
    "options": [
      {
        "id": 3,
        "title": "Dimension",
        "is_color_option": 0,
        "items": [
          {
            "id": 19,
            "value": "40x60cm"
          },
          {
            "id": 20,
            "value": "60x90cm"
          },
          {
            "id": 21,
            "value": "80x120cm"
          }
        ]
      }
    ],
    "description": "The best is yet to come! Give your walls a voice with a framed poster. This aesthethic, optimistic poster will look great in your desk or in an open-space office. Painted wooden frame with passe-partout for more depth.",
    "reference": "demo_6",
    "category_name": "art",
    "manufacturer_name": "Graphic Corner",
    "product_info": [
      {
        "name": "Brand",
        "value": "Graphic Corner"
      },
      {
        "name": "SKU",
        "value": "demo_6"
      },
      {
        "name": "Condition",
        "value": "New"
      },
      {
        "name": "Composition",
        "value": "Matt paper"
      }
    ],
    "accessories": [],
    "customization_fields": {
      "is_customizable": "0",
      "customizable_items": []
    },
    "pack_products": [],
    "seller_info": [],
    "product_attachments_array": [],
    "product_url": "https://rest.binshops.com/en/art/3-the-best-is-yet-to-come-framed-poster.html",
    "groups": {
      "3": {
        "group_name": "Dimension",
        "name": "Dimension",
        "group_type": "select",
        "default": 19,
        "attributes": {
          "19": {
            "name": "40x60cm",
            "html_color_code": "",
            "texture": "",
            "selected": false
          },
          "20": {
            "name": "60x90cm",
            "html_color_code": "",
            "texture": "",
            "selected": false
          },
          "21": {
            "name": "80x120cm",
            "html_color_code": "",
            "texture": "",
            "selected": false
          }
        },
        "attributes_quantity": {
          "19": 900,
          "20": 300,
          "21": 300
        }
      }
    },
    "breadcrumb": [
      {
        "title": "Home",
        "url": "https://rest.binshops.com/en/"
      },
      {
        "title": "Art",
        "category_id": 9,
        "url": "https://rest.binshops.com/en/9-art"
      }
    ]
  }
}

Does PrestaShop have API?

PrestaShop has Webservices API out-of-the-box to access database tables through CRUD operations, however the PrestaShop REST API module makes it easier to build front-end applications and to integrate PrestaShop with other systems.

PrestaShop Webservices API and REST API Module

You may be a developer or a project manager who is looking for a way to communicate with your PrestaShop website to build your mobile application, or any client side app which is developed by ReactJs, AngularJs or VueJs application. So, you search for the PrestaShop API, and you reach to the PrestaShop Webservice API. Let's see what it is and why you may need a REST API module.

The products that use this REST API

Modern PrestaShop PWA, SSR rendered and SEO optimized.

PrestaShop Mobile Application, high performance eCommerce mobile application.

Why PrestaShop Webservice API is not enough?

In short, native PrestaShop Webservice API is intended for CRUD operations, but the API module is intended to work with Business Logics.

PrestaShop Webservice API

As you know, PrestaShop has a Webservice API out-of-the-box which gives PrestaShop websites the ability to access their shop's database through CRUD (PrestaShop Webservice API). With Webservice API you can perform the four common operations on your website's data (CRUD - Create, Read, Update, Delete) and it's a nice feature if you want to connect another software to your website and manage your data. You can manipulate your User Account, Orders, Products etc, through this feature. To use this feature you will also need to generate a token in back-office and you give appropriate permissions to it.

But, in some cases like building front-end applications, CRUD APIs are not enough. Instead, working with business logic APIs could make the development process much easier.

What is the challenge with PrestaShop Webservice API?

Let's suppose that you want to have a mobile application or a PWA for your PrestaShop website. Does this fulfill all of our API requirements? or do we still need something else? The existing Webservice API does not fulfill all of our requirements because:

  1. When you use Webservice API and you assign permissions to your token, handling access control will be complicated. Let's suppose that you grant write access for Account model to your token. So, anyone with the token can edit any user account.
  2. For example, we want to add an item to our cart, though we can add items to a cart through these APIs, but we do not know the logic behind it, and we MUST implement all of the logic for cart functionality. Which logics? context parameters, hooks that are triggered when we add an item to the cart, or many other logics which resides here.
  3. And the most important point is that, imagine you've implemented all the business logics for a feature, but what about PrestaShop core changes and updates? You must keep the module update-to-dated with latest PrestaShop changes. But think about a module that acts as a layer on top of the PrestaShop core logic to expose the APIs.

Binshops REST API module covers all of these concerns.

Binshops REST API

Binshops REST Module exposes REST API endpoints for any Prestashop website. This module does not require the Prestashop's Webservices feature to be enabled. Totally free without any restriction. Available Endpoints:

  • Bootstrap: to get required data for home page
    • Menu Items
    • Featured products
    • Slider
    • Banner Image
  • Authentication
    • Login
    • Register
    • Logout
  • Profile/Account
    • Account Info
    • Account Edit
    • New Password
    • Reset Password
  • Wishlist
    • List Wishlists
    • Create/delete Wishlists
    • Add/remove product to/from Wishlists
  • Products
    • Product Detail
    • Category Products
    • Product Search
    • Faceted Search
    • Featured Products
  • Address
    • All Addresses
    • Add New Address
    • Get Address
    • Delete Address
  • Checkout
    • Set Address
    • List All Addresses
    • Set Carrier
    • Payment Options
  • Cart
    • Add to Cart
    • Remove from Cart
    • Show Cart Items

Youtube Video

Postman Documentation

You can access full documentation for REST endpoints on Postman publisher: Postman Doc

Do you need API customization for your PrestaShop website? submit your request.