Jump to content

SOLVED: 405 method not allowed when POST.


Recommended Posts

Hi.

I am sending this request with Restman (no matter I use http or https, I get the same response, and using basic authentication) becasue I want to update the stock of my products through the API

URL: http://farmaciasbaratas.com/api/stock_availables

with this xml in the response

<?xml version="1.0" encoding="UTF-8" ?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
   <stock_availables>
        <stock_available>
            <id>
                <![CDATA[1062]]>
            </id>
              <id_product_attribute><![CDATA[0]]></id_product_attribute>
            <quantity>
                <![CDATA[1]]>
            </quantity>
              <depends_on_stock><![CDATA[0]]></depends_on_stock>
            <out_of_stock><![CDATA[2]]></out_of_stock>
  </stock_available>
   </stock_availables>
</prestashop>

I always get 405 method not allowed when POST. I don't know why, as I granted all permissions for products and stock_availables in the webservice admin page of my site. I was wondering perhaps not using all required files, but I checked in the documentation (https://devdocs.prestashop.com/1.7/webservice/resources/stock_availables/), and I think nothing is missing.

If I use GET instead, everything works fine. As I said, I granted all permissions.

Any idea what could be going on?

Thank you.

Edited by Xavi_
Solved (see edit history)
Link to comment
Share on other sites

I found the reason.

POST is to add new records. Since I was trying to modify the information of an existing record, I should use PUT instead.

It works with a 200 OK response if I PUT, with the following body

 

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<stock_available>
    <id><![CDATA[1]]></id>
    <id_product><![CDATA[1]]></id_product>
    <id_product_attribute><![CDATA[0]]></id_product_attribute>
    <id_shop><![CDATA[1]]></id_shop>
    <id_shop_group><![CDATA[0]]></id_shop_group>
    <quantity><![CDATA[2399]]></quantity>
    <depends_on_stock><![CDATA[0]]></depends_on_stock>
    <out_of_stock><![CDATA[2]]></out_of_stock>
    <location></location>
</stock_available>
</prestashop>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...