Magento 2 REST API Authentication
Get Product By SKU REST API Magento 2
//Authentication rest API magento2.Please change url accordingly your url $adminUrl='http://127.0.0.1/magento2/index.php/rest/V1/integration/admin/token'; $ch = curl_init(); $data = array("username" => "wsuser", "password" => "password123"); $data_string = json_encode($data); $ch = curl_init($adminUrl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string)) ); $token = curl_exec($ch); $token= json_decode($token);
Get Product By SKU REST API Magento 2
//Use above token into header $headers = array("Authorization: Bearer $token"); $requestUrl='http://127.0.0.1/magento2/index.php/rest/V1/products/24-MB01'; //Please note 24-MB01 is sku $ch = curl_init(); $ch = curl_init($requestUrl); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); $result= json_decode($result); print_r($result);
1 comments:
commentsI together with my guys have been viewing the best thoughts from your web site while unexpectedly got an awful suspicion I never expressed respect to you for those secrets. These young men became for that reason stimulated to see all of them and have now in truth been making the most of these things. Many thanks for indeed being indeed kind as well as for picking this kind of tremendous issues millions of individuals are really needing to understand about. Our sincere apologies for not saying thanks to you earlier.magento
Reply