Hello Magento Friends,
In today’s blog post, I am going to explain How to Get Child Product of Configurable Product using REST API in Magento 2.
Magento supports various product types and one of them is Configurable Products. When you need to provide options for a single product, you need to create configurable products in Magento 2.
Configurable products have various child products. Say, for example, you are selling a t-shirt with a t-shirt design maker and you want to provide color and size options to the customers. Then, the t-shirt is a configurable product while color and size options are its child products.
Let’s see How to Get Child Product of Configurable Product using REST API in Magento 2.
Contents
Step 1: Create a getchildproductinfo.php file anywhere and add the following code
<?php $baseUrl = "http://yourdomain"; $userData = array("username" => "admin", "password" => "admin@123"); $ch = curl_init($baseUrl."/rest/V1/integration/admin/token"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData)))); $token = curl_exec($ch); $ch = curl_init($baseUrl."/rest/all/V1/configurable-products/WSH01/children"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token))); $result = curl_exec($ch); $result = json_decode($result, 1); echo '<pre>'; print_r($result); echo '</pre>'; ?>
This way you can retrieve child products of configurable product with the help of REST API in Magento 2. If you have any doubts about the above code let me know through the comments. Share the article further and stay updated with us
Happy Coding!
In modern web development, seamless navigation and state management are crucial for delivering a smooth…
Magento Open Source 2.4.8 beta version released on October 8, 2024. The latest release of…
Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…
As the world of eCommerce continues to thrive, Shopify has become one of the most…
Shopify Remix is an innovative framework that provides a streamlined experience for building fast, dynamic,…
Building a successful eCommerce store requires expertise, and for many businesses, Shopify has become the…