Reputation: 1430
I Followed the instruction of this page http://www.magentocommerce.com/api/rest/Resources/inventory.html#RESTAPI-Resource-StockItems-HTTPMethod-PUT-stockitems--id and I have this code:
$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = $apiUrl.'/stockitems/429';
$productData = json_encode(array(
'qty' => 982,
'is_in_stock' => 1
));
$headers = array('Content-Type' => 'application/json');
$oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers);
print_r($oauthClient->getLastResponseInfo());
But I get the return
[message:protected] => Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)
I tried with XML like this:
$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = $apiUrl.'/stockitems/429';
$productData = '<?xml version="1.0"?>
<magento_api>
<qty>99</qty>
</magento_api>';
$headers = array('Content-Type' => 'text/xml');
$oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers);
print_r($oauthClient->getLastResponseInfo());
and I get the error:
[message:protected] => Invalid auth/bad request (got a 405, expected HTTP/1.1 20X or a redirect)
I don't know what I'm doing wrong?
Thank you for your reply.
Upvotes: 1
Views: 2736
Reputation: 634
Make sure you assigned to your admin user REST role.
Configuring Permissions Step By Step:
Upvotes: 0
Reputation: 189
Another way to update item's quantity is to call the /products/:id API, method = PUT, with the following payload:
{"stock_data" : {"qty" : "123"}}
Upvotes: 1
Reputation: 756
You are using POST instead of PUT. HTTP Post is used for creating items in Magento, but if you update an item (or inventory, image, whatever) by id you have to use PUT.
Upvotes: 0