Read More
Read More
Menu Close

    PrestaShop Webservices : PUT method issue

    PrestaShop webservices use the REST architecture to comply with most of the platforms. It supports most of the popular HTTP methods i.e. GET, POST, PUT, DELETE and HEAD methods, each for a specific purpose. For example, GET request for fetching data, POST for creating data and PUT for updating data in PrestaShop.

    Most of the production ready servers block the PUT requests for security purposes. This is because the PUT and DELETE methods originally intend as file management operations so these are considered unsafe to keep open without any prior authentication like a token. However, in case of PrestaShop webservices, this security feature becomes a problem because now the API cannot update data in PrestaShop.

    Solution : ps_method parameter

    To solve this, PrestaShop has provided an extra parameter “ps_method”. We will discuss how to use this parameter to wrap the HTTP method so that the intended API method is considered at PrestaShop end.

    The idea is to keep the request HTTP method as “POST”, and add en extra URL parameter “ps_method” in the request URL. The value of this parameter is the HTTP method you want to call. In our case, it is “PUT”. Let’s understand with the help of an example:

    When you call a request with PUT method and if the server blocks this method, you may get any of these error messages:

    Start your headless eCommerce
    now.
    Read More
    • 405 Method Not Allowed
    • 403 Forbidden

    Sometimes it also gives 404 Not found but that is very rare. So it is very easy to identify if the API server is blocking the request. Let’s say we called the following URL with PUT request:

    http://localhost/PrestaShop/api/addresses/1?ws_key=IHMEWSE7L3GU92JVZ4K7W222TPYP127U

    This request failed with one of the above messages, so we will use the ps_method parameter to convert the request into PUT method while also keeping it POST request for the server:

    http://localhost/PrestaShop/api/addresses/1?ws_key=IHMEWSE7L3GU92JVZ4K7W222TPYP127U&ps_method=PUT

    It solves the problem as the request is actually a POST request, but the PrestaShop identifies the ps_method parameter and considers the request as PUT request. Now the data will be updated successfully with proper 201 response.

    That’s all about the solution to PUT request issue in PrestaShop webservices. If any issue or doubt in the above process, please feel free to let us know in the comment section.

    I would be happy to help.

    Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

    For any doubt contact us at [email protected].

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top