{"action":"created","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/5827","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/5827/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/5827/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/5827/events","html_url":"https://github.com/magento/magento2/issues/5827","id":167792930,"number":5827,"title":"Problem in Product Add Edit using REST API","user":{"login":"radhagobinda","id":19976130,"avatar_url":"https://avatars.githubusercontent.com/u/19976130?v=3","gravatar_id":"","url":"https://api.github.com/users/radhagobinda","html_url":"https://github.com/radhagobinda","followers_url":"https://api.github.com/users/radhagobinda/followers","following_url":"https://api.github.com/users/radhagobinda/following{/other_user}","gists_url":"https://api.github.com/users/radhagobinda/gists{/gist_id}","starred_url":"https://api.github.com/users/radhagobinda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radhagobinda/subscriptions","organizations_url":"https://api.github.com/users/radhagobinda/orgs","repos_url":"https://api.github.com/users/radhagobinda/repos","events_url":"https://api.github.com/users/radhagobinda/events{/privacy}","received_events_url":"https://api.github.com/users/radhagobinda/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-27T07:53:36Z","updated_at":"2016-07-27T09:15:52Z","closed_at":null,"body":"I cannot add or edit product using REST Api . Its always through message \"<b>Consumer is not authorized to access %resources</b>\". I have checked several times but i con't. Access token is fine.\r\n\r\n### Share my code\r\n\r\n$adminUrl=\"http://192.168.1.23/magento2/index.php/rest/V1/integration/admin/token\";\r\n\t$ch = curl_init();\t\r\n        $data = array(\"username\" => \"super_admin\", \"password\" =>\"admin123\");\r\n\t$data_string = json_encode($data);                       \r\n\t$ch = curl_init($adminUrl); \r\n\tcurl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"POST\");                                                                     \r\n\tcurl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  \r\n\tcurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      \r\n\tcurl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          \r\n\t    'Content-Type: application/json',                                                                                \r\n\t    'Content-Length: ' . strlen($data_string))                                                                       \r\n\t);       \r\n\t$token = curl_exec($ch);\r\n\t$token=  json_decode($token);\r\n\r\n$headers = array(\"Authorization: Bearer $token\"); \r\n    \r\n    $requestUrl='http://192.168.1.23/magento2/index.php/rest/V1/products';\r\n\r\n    $ch = curl_init($requestUrl); \r\n    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); \r\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   \r\n    curl_setopt($ch, CURLOPT_POST, true);\r\n    \r\n   $post ='{\r\n  \"product\": {\r\n    \"sku\": \"MY_SKU\",\r\n    \"name\": \"My Product\",\r\n    \"attributeSetId\": \"4\",\r\n    \"price\": 20,\r\n    \"status\": 1,\r\n    \"visibility\": 4,\r\n    \"typeId\": \"virtual\",\r\n    \"weight\": 0,\r\n    \"extensionAttributes\": {\r\n      \"stockItem\": {\r\n        \"stockId\": 1,\r\n        \"qty\": 20,\r\n        \"isInStock\": true,\r\n        \"isQtyDecimal\": false,\r\n        \"useConfigMinQty\": true,\r\n        \"minQty\": 0,\r\n        \"useConfigMinSaleQty\": 0,\r\n        \"minSaleQty\": 0,\r\n        \"useConfigMaxSaleQty\": true,\r\n        \"maxSaleQty\": 0,\r\n        \"useConfigBackorders\": false,\r\n        \"backorders\": 0,\r\n        \"useConfigNotifyStockQty\": true,\r\n        \"notifyStockQty\": 20,\r\n        \"useConfigQtyIncrements\": false,\r\n        \"qtyIncrements\": 0,\r\n        \"useConfigEnableQtyInc\": false,\r\n        \"enableQtyIncrements\": false,\r\n        \"useConfigManageStock\": true,\r\n        \"manageStock\": true,\r\n        \"lowStockDate\": \"string\",\r\n        \"isDecimalDivided\": true,\r\n        \"stockStatusChangedAuto\": 0,\r\n        \"extensionAttributes\": {}\r\n      }\r\n    },\r\n    \"options\": [],\r\n    \"tierPrices\": [],\r\n    \"customAttributes\": [\r\n    ]\r\n  },\r\n  \"saveOptions\": true\r\n}';\r\n\r\n    $options = array(\r\n        //CURLOPT_URL=>$requestUrl,\r\n        CURLOPT_HTTPHEADER=>array(                                                                          \r\n        'Content-Type: application/json',                                                                                \r\n        'Content-Length: ' . strlen($post)),\r\n        CURLOPT_VERBOSE=>0,\r\n        CURLOPT_RETURNTRANSFER=>true,\r\n        CURLOPT_USERAGENT=>\"Mozilla/4.0 (compatible;)\",\r\n        CURLOPT_POST=>true,\r\n        CURLOPT_POSTFIELDS=>$post,\r\n\r\n    );\r\n    curl_setopt_array($ch, $options);\r\n    $result = curl_exec($ch);\r\n    $result=  json_decode($result);\r\n    return $result;\r\n\r\n### Actual result\r\n<!--- Tell us what happens instead -->\r\n\r\n**It's returned**\r\nstdClass Object\r\n(\r\n    [message] => Consumer is not authorized to access %resources\r\n    [parameters] => stdClass Object\r\n        (\r\n            [resources] => Magento_Catalog::products\r\n        )\r\n\r\n) \r\n\r\nPlease anyone tell me what wrong with my code. And user role is **administrator**. \r\n"},"comment":{"url":"https://api.github.com/repos/magento/magento2/issues/comments/235531855","html_url":"https://github.com/magento/magento2/issues/5827#issuecomment-235531855","issue_url":"https://api.github.com/repos/magento/magento2/issues/5827","id":235531855,"user":{"login":"radhagobinda","id":19976130,"avatar_url":"https://avatars.githubusercontent.com/u/19976130?v=3","gravatar_id":"","url":"https://api.github.com/users/radhagobinda","html_url":"https://github.com/radhagobinda","followers_url":"https://api.github.com/users/radhagobinda/followers","following_url":"https://api.github.com/users/radhagobinda/following{/other_user}","gists_url":"https://api.github.com/users/radhagobinda/gists{/gist_id}","starred_url":"https://api.github.com/users/radhagobinda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radhagobinda/subscriptions","organizations_url":"https://api.github.com/users/radhagobinda/orgs","repos_url":"https://api.github.com/users/radhagobinda/repos","events_url":"https://api.github.com/users/radhagobinda/events{/privacy}","received_events_url":"https://api.github.com/users/radhagobinda/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T09:15:52Z","updated_at":"2016-07-27T09:15:52Z","body":"I have already put it in options array.\r\n\r\n$options = array(\r\n    //CURLOPT_URL=>$requestUrl,\r\n    CURLOPT_HTTPHEADER=>array(                                                                          \r\n    'Content-Type: application/json',                                                                                \r\n    'Content-Length: ' . strlen($post)),\r\n    CURLOPT_VERBOSE=>0,\r\n    CURLOPT_RETURNTRANSFER=>true,\r\n    CURLOPT_USERAGENT=>\"Mozilla/4.0 (compatible;)\",\r\n    CURLOPT_POST=>true,\r\n    CURLOPT_POSTFIELDS=>$post,\r\n\r\n);\r\n\r\nThis is not working."}}
{"actor":{"display_login":"radhagobinda"}}