How to add product using REST api.
Getting below error -
Invalid auth/bad request (got a 500, expected HTTP/1.1 20X or a redirect)
Service temporary unavailable
I tried,
$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
For above error Solution
In admin,
System -> Permissions -> Users -> Rest Role -> Select Admin.
-
Did you take a look at the documentation at Magento devdocs.magento.com/guides/m1x/api/rest/introduction.htmlArjen Miedema– Arjen Miedema2017年03月30日 07:20:38 +00:00Commented Mar 30, 2017 at 7:20
-
@ArjenMiedema - Thanks, Now I will go through the link.jassi– jassi2017年03月30日 07:27:20 +00:00Commented Mar 30, 2017 at 7:27
1 Answer 1
Step to Add Product Using REST Api
Step-1: Admin Configuration
- Create user Role Go to system>Web services>REST - Roles: Click on Add Admin Role and create an Admin Role for REST. Role info: Provide the role name example 'Admin'
Resource Access: Set :All Role Users: Select and admin user to whom you wish to provide Admin REST role
- Go to system>Web services>REST Attributes: Select Admin
Set: Resource Access as "All"
- Go to system>Web services>OAUTH Consumers:
Click on 'Add New' button, it will create a new Oauth consumer, note down the Consumer Key and Consumer secret.
Step-2 : script for create new product via REST API
create test_api.php file at your host example: location: http://yourdomain/test_api.php you have to post below fields in json encode format
$productData = json_encode(array(
'type_id' => 'simple',
'attribute_set_id' => 4,
'sku' => 'simple' . uniqid(),
'weight' => 1,
'status' => 1,
'visibility' => 4,
'name' => 'Simple Product',
'description' => 'Simple Description',
'short_description' => 'Simple Short Description',
'price' => 99.95,
'tax_class_id' => 0,
));
see code sample at URL: http://devdocs.magento.com/guides/m1x/api/rest/introduction.html#root
-
I got error - Fatal error: Class 'OAuth' not found in C:\xampp\htdocs\magento1.9\magento\test_api.php on line 19jassi– jassi2017年03月30日 09:42:10 +00:00Commented Mar 30, 2017 at 9:42
-
please check extension=oauth.so into your php.ini if not found then put extension=oauth.so in php.ini if staill not working Installing PHP Extension for Oauth : 1. Download php_oauth.dll file and add it under C:\xampp\php\ext\ 2. add [PHP_OAUTH] extension=php_oauth.dll in php.iniRajesh Hothi– Rajesh Hothi2017年03月30日 10:09:55 +00:00Commented Mar 30, 2017 at 10:09
-
I have done above steps again and now that error is not coming. But product is not getting added and getting below error. [message:protected] => Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)jassi– jassi2017年03月30日 12:00:36 +00:00Commented Mar 30, 2017 at 12:00
-
If i try to get products using www.abc.com/api/rest/products i getting 404 error. How can i solve this issue? Is necessary oAuth should be installed in server? @Piyushzus– zus2018年10月25日 12:20:40 +00:00Commented Oct 25, 2018 at 12:20