{"action":"opened","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/12190","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/12190/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/12190/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/12190/events","html_url":"https://github.com/magento/magento2/issues/12190","id":273132785,"number":12190,"title":"M2.2.x: Products not being removed from website via REST API","user":{"login":"thomvanderboon","id":16068454,"avatar_url":"https://avatars3.githubusercontent.com/u/16068454?v=4","gravatar_id":"","url":"https://api.github.com/users/thomvanderboon","html_url":"https://github.com/thomvanderboon","followers_url":"https://api.github.com/users/thomvanderboon/followers","following_url":"https://api.github.com/users/thomvanderboon/following{/other_user}","gists_url":"https://api.github.com/users/thomvanderboon/gists{/gist_id}","starred_url":"https://api.github.com/users/thomvanderboon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomvanderboon/subscriptions","organizations_url":"https://api.github.com/users/thomvanderboon/orgs","repos_url":"https://api.github.com/users/thomvanderboon/repos","events_url":"https://api.github.com/users/thomvanderboon/events{/privacy}","received_events_url":"https://api.github.com/users/thomvanderboon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-11T09:28:43Z","updated_at":"2017-11-11T09:28:43Z","closed_at":null,"author_association":"NONE","body":"Under M2,1,x I was able to add and remove a product to a website using the REST API. Under M2.2.x adding a product to a website via rest works, but removing the product from the website does not work.\r\n\r\n### Preconditions\r\n1. Ubuntu 16.04 LTS\r\n2. PHP 7.0.22\r\n3. Extra user in database to handle rest via tokens\r\n\r\n### Steps to reproduce\r\n1. Create a product and a extra website \r\n2. Run the following script:\r\n\r\n\r\n```\r\n<?php\r\n\r\n$sku = \"5000001_STUK\"; // Change your SKU to match a product in your database\r\n\r\n//Authentication rest API magento2.Please change url accordingly your url\r\n$adminUrl='http://shop.domain.com/rest/V1/integration/admin/token';\r\n$ch = curl_init();\r\n$data = array(\"username\" => \"rest_user\", \"password\" => \"Some_secret_password\");\r\n$data_string = json_encode($data);\r\n$ch = curl_init($adminUrl);\r\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"POST\");\r\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\ncurl_setopt($ch, CURLOPT_HTTPHEADER, array(\r\n    'Content-Type: application/json',\r\n    'Content-Length: ' . strlen($data_string))\r\n);\r\n$token = curl_exec($ch);\r\n$token=  json_decode($token);\r\necho \"Token: \" .$token . \"\\n\";\r\ncurl_close($ch);\r\n\r\n//Use above token into header\r\n$headers = array(\"Authorization: Bearer $token\");\r\n\r\n\r\n// Remove product from website id 1\r\n\r\n$headers = array(\"Authorization: Bearer $token\",\"Content-Type: application/json\");\r\n$requestUrl=\"http://shop.domain.com/index.php/rest/V1/products/\".$sku.\"/websites/1\";\r\n$ch = curl_init();\r\n$ch = curl_init($requestUrl);\r\n//curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);\r\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"DELETE\");\r\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\n$curl_result = curl_exec($ch);\r\n$responseInfo = curl_getinfo($ch);\r\n$httpResponseCode = $responseInfo['http_code'];\r\necho $httpResponseCode;\r\nprint_r($curl_result);\r\ncurl_close($ch);\r\n\r\n// Add product to wesite id 2\r\n\r\n$sampleProductData = array(\r\n  'sku' => $sku,\r\n  'website_id' => 2,\r\n  );\r\n$data_string = json_encode(array('productWebsiteLink' => $sampleProductData));\r\n\r\n$requestUrl=\"http://shop.domain.com/index.php/rest/V1/products/\".$sku.\"/websites\";\r\n$ch = curl_init();\r\n$ch = curl_init($requestUrl);\r\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);\r\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"PUT\");\r\ncurl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\n$curl_result = curl_exec($ch);\r\nprint_r($curl_result);\r\ncurl_close($ch);\r\n?>\r\n```\r\n\r\n\r\n### Expected result\r\n1. Product is removed from website id 1 and added to website id 2\r\n\r\n### Actual result\r\n1. Product NOT removed from website id 1, Product is correctly added to website id 2\r\n\r\nTested against my backup 2.1.9. Above script works perfect on M2.1.9 \r\n"}}
{"actor":{"display_login":"thomvanderboon"}}