PrestaShop Module Webservice API: How to create it?

 

PrestaShop is one of the best open source CMS platforms available out there. We are assuming that you must be well aware about PrestaShop and you must have a fair amount of knowledge about the software. Reason being that we have already written a lot on the subject, in this little discourse we will limit our discussion to the creation of PrestaShop Module webservice API.

The Creation Process

PrestaShop contains a Webservice API for the PrestaShop tables which are core in nature. As a user you can easily get the PrestaShop Webservice API activated from the “tab advanced parameters-> Webservice”.

  • Get the PrestaShop Webservice enabled from the configuration panel
  • From the toolbar button, add the webservice key. Inspect the checkbox for the resources and generate key

You can get relevant access to the API from the URL mentioned below:

 

“http:://example.com/api/”

 

If you really want to develop an API for the PrestaShop modules then for this you need to add the module resources in the list of PrestaShop webservice. This can be done by superseding webservice request class “getResources() function (dir  /classes/”

In the code mentioned above:

  •  For the PrestaShop Productcomment module we have developed a resource for the class Productcomment
  •  Each resource can be well defined provided your table is equipped with a class. You need to give a class name “$resources var array”
  • A hook by the name of “addMobikulResources” has been added by us. You can utilize this hook in some other module for the purpose of adding additional resources.

In the webservice tab page you can easily see the name of Productcomment resource. Be smart enough to inspect the permission for the resources. Once inspected, save!

You can find the details pertaining to table xml by visiting http://example.com/api/productcomment/page

 

Utilize Specific Management: It is Important!

In case you do not possess any class for the table then in such a situation you need to utilize “specific_management’ => true”

“$resources['myresource'] = array('description' => 'Manage My API', 'specific_management' => true);”

Now develop a file in the module classes. The name of the folder is: “WebserviceSpecificManagementMyResource.php”

The prefix of this particular file name should be “WebserviceSpecificManagement”

The code in this particular file should be similar to WebserviceSpecificManagementImages.php class in  /classes/webservice/ directory or WebserviceSpecificManagementSearch.php along the following mentioned details

  • The interface of WebserviceSpecificManagement is implemented
  • The body of four methods is defined i.e. getWsObject, setObjectOutput, setWsObject and getObjectOutput
  • The required code can be written in the manage function

Now you can easily access the API available on the URL: http://example.com/api/myresource/
 

Get Started: Do not Waste time!

The process mentioned above is very easy and you do not need to worry in this regard. You can find many tutorials on the internet in this regard which surely serves a plus point for you as far as learning of the art is concerned. Take the first step and everything will be easy


 

 

 

Leave your comments

0
terms and condition.
  • No comments found
Video Mobile Converter