Posted in:
Magento REST API
Magento 2 get products by sku using REST API
This Blog instructs you that how to get the products by SKU using REST API. In Magento 2, You can get the corresponding product details by using following commands.
$magento_url = “YOUR_MAGENTO_BASE_URL”;
$magento_token = “TOKEN”;
If you don’t know how to get token then you must see this blog post Magento 2 GET REST API
$sku = "test123_2";
$ch = curl_init($magento_url . "/rest/all/V1/products/".$sku);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . $magento_token));
$product = curl_exec($ch);
$product = json_decode($product, 1);
print_r($product);
OutPut
Array
(
[id] => 2
[sku] => test123_2
[name] => Test Product 2
[attribute_set_id] => 4
[price] => 5
[status] => 1
[visibility] => 4
[type_id] => simple
[created_at] => 2020-06-02 12:26:54
[updated_at] => 2021-01-16 11:35:52
[weight] => 3
[extension_attributes] => Array
(
[website_ids] => Array
(
[0] => 1
)
[category_links] => Array
(
[0] => Array
(
[position] => 0
[category_id] => 3
)
[1] => Array
(
[position] => 0
[category_id] => 8
)
)
[stock_item] => Array
(
[item_id] => 9
[product_id] => 2
[stock_id] => 1
[qty] => 57034
[is_in_stock] => 1
[is_qty_decimal] =>
[show_default_notification_message] =>
[use_config_min_qty] => 1
[min_qty] => 0
[use_config_min_sale_qty] => 0
[min_sale_qty] => 1
[use_config_max_sale_qty] =>
[max_sale_qty] => 1000
[use_config_backorders] => 1
[backorders] => 0
[use_config_notify_stock_qty] => 1
[notify_stock_qty] => 1
[use_config_qty_increments] => 1
[qty_increments] => 0
[use_config_enable_qty_inc] => 1
[enable_qty_increments] =>
[use_config_manage_stock] =>
[manage_stock] => 1
[low_stock_date] =>
[is_decimal_divided] =>
[stock_status_changed_auto] => 0
)
)
[product_links] => Array
(
)
[options] => Array
(
)
[media_gallery_entries] => Array
(
[0] => Array
(
[id] => 29
[media_type] => image
[label] =>
[position] => 1
[disabled] =>
[types] => Array
(
[0] => image
[1] => small_image
[2] => thumbnail
[3] => swatch_image
)
[file] => /w/s/ws06-purple_main.jpg
)
[1] => Array
(
[id] => 30
[media_type] => image
[label] =>
[position] => 2
[disabled] =>
[types] => Array
(
)
[file] => /m/h/mh03-black_main.jpg
)
)
[tier_prices] => Array
(
)
[custom_attributes] => Array
(
[0] => Array
(
[attribute_code] => image
[value] => /w/s/ws06-purple_main.jpg
)
[1] => Array
(
[attribute_code] => url_key
[value] => test-product-2
)
[2] => Array
(
[attribute_code] => gift_message_available
[value] => 2
)
[3] => Array
(
[attribute_code] => conv_enable_subscription
[value] => 0
)
.
.
.
.
.
.
.
.
[26] => Array
(
[attribute_code] => color
[value] => 5431
)
)
)
You can get the Products by ID, Click on Magento 2 get products by ID using REST API
February 16, 2021
Did you like this post?