Hello Magento Friends,
In our Magento 2 Tutorial series on SOAP API, today I am going to explain How to Get Category Information Using SOAP API in Magento 2.
SOAP API is the connection between the Magento 2 and external systems to transfer data smoothly. When you need the product, category, order, or any other information outside the Magento platform, you can use the SOAP API in Magento 2.
Contents
Magento 2 stores hold various categories for the products. Categories help to organize products in a way that makes it easy for the customer and admin both to locate the product quickly.
This blog is used to get a category tree (category information) using SOAP API. There are two ways to get category information: First, is to get all the categories and the Second is to get specific categories using category ID.
Here I have explained both the methods to Get Category Information Using SOAP API in Magento 2.
Step 1: Create getCatTreeSoap.php file anywhere and add the following code
<?php // changes your store url. $request = new SoapClient("http://yourdomain/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2)); $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"youradminusername", "password"=>"youradminpassword")); // changes your store url. $request = new SoapClient( 'http://yourdomain/soap/default?wsdl&services=catalogCategoryManagementV1', array( 'soap_version' => SOAP_1_2, 'stream_context' => stream_context_create(array( 'http'=> array('header' => 'Authorization: Bearer '.$token->result) )) ) ); $response = $request->catalogCategoryManagementV1GetTree(); echo "<pre>"; print_r($response); echo "</pre>"; ?>
Step 1: Create getCatTreeSoap.php file anywhere and add the following code
<?php // changes your store url. $request = new SoapClient("http://yourdomain/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2)); $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"youradminusername", "password"=>"youradminpassword")); // changes your store url. $request = new SoapClient( 'http://yourdomain/soap/default?wsdl&services=catalogCategoryRepositoryV1', array( 'soap_version' => SOAP_1_2, 'stream_context' => stream_context_create(array( 'http'=> array('header' => 'Authorization: Bearer '.$token->result) )) ) ); $response = $request->catalogCategoryRepositoryV1Get(array("categoryId" => 13)); echo "<pre>"; print_r($response); echo "</pre>"; ?>
This way you can get all category and specific category information using SOAP API in Magento 2. In case of any errors, reach out to me in the comment section. Share the article with your friends and stay in touch with us for more tutorials on SOAP API in Magento 2.
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…