How To

How to Get Category Information Using SOAP API in Magento 2

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.

Introduction:

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.

How to Get Category Information Using SOAP API in Magento 2:

Method 1: Get All Category Information

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>";

?>

Method 2: Get Specific Category Information using Category ID

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>";

?>

Conclusion:

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!

Click to rate this post!
[Total: 4 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

17 hours ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

3 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

3 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

4 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

5 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

7 days ago