After adding product to Magento run http://mymagentohost/api/rest/products/40
it will return Resource not found
but if just open product from Magento and click on save
(without changing anything) than (run http://mymagentohost/api/rest/products/40
) it will return product in xml view.
some code for saving product using REST OAuth as below
$this->productData = array(
'type_id' => 'activities',
'attribute_set_id' => 4,
'sku' => 'activities' . uniqid(),
'status' => 1,
'visibility' => 4,
'name' => 'Activities Product',
'description' => 'Activities Description',
'price' => 10.00,
'sm_product_vendor_id' => 23,
'category_id' => 1,
'tax_class_id' => 0,
........);
function saveProduct(){
try {
$oauthClient = new OAuth($this->consumerKey, $this->consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $this->authType);
$oauthClient->enableDebug();
$oauthClient->setToken($this->token, $this->secret);
$headers = array('Content-Type' => 'application/json');
$oauthClient->fetch($this->resourceUrl, $this->productData, "POST", $headers);
$this->responceInfo = $oauthClient->getLastResponseInfo();
$this->responce = $oauthClient->getLastResponse();
} catch (OAuthException $e) {
$this->oauthError=$e;
}
}
$this->saveProduct();
Response Info
....
[headers_recv] => HTTP/1.1 200 OK
Date: Wed, 14 Aug 2013 03:15:59 GMT
Server: Apache/2.2.22 (Win32) mod_ssl/2.2.22 OpenSSL/0.9.8o
X-Powered-By: PHP/5.3.14 ZendServer
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
Set-Cookie: PHPSESSID=rrom4add03f0ikrt6d51ej9gi5; expires=Wed, 14-Aug-2013 04:16:00 GMT; path=/magento; domain=localhost; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
/api/rest/products/40
.....
when i try to run http://mymagentohost/api/rest/products/40
it will return Resource not found
<magento_api><messages><error><data_item><code>404</code><message>Resource not found.</message></data_item></error></messages></magento_api>
Edit
while adding product via REST API following data not inserted in table (2 tables) .
if i manually add following data in table than it will be retrieved via REST API.
how to add this records using REST API
magento_catalog_product_index_price
magento_catalog_product_website
Best Answer
Was able to solve this by creating a custom REST API module that pretty much does this;
Replace 1 with website_id which is needed. I call this after saving the product as a separate API call. It could be inserted to the REST API in the core of course right after
$product->save();
I did not find it necessary to add anything to
magento_catalog_product_index_price
Pity Magento CE is not really open source so cannot do a pull request - it's more like "dumpsourceware".