How To

Magento 2: How to Update Specific Product Quantities using SOAP API?

Hello Magento Friends,

In this blog, I will explain How to Update Specific Product Quantities using SOAP API in Magento 2.

When you are in need to update quantities of a specific product, you can accomplish it using SOAP API. Let’s find out How to Update Specific Product Quantities using SOAP API in Magento 2.

Steps to Update Specific Product Quantities using SOAP API in Magento 2:

Step 1: Create a file in your Magento root directory at the below path

magento_root_directory\call_soap.php

Now add the below code

<?php
use Magento\Framework\App\Bootstrap;

try {
 require './app/bootstrap.php';
 $bootstrap = Bootstrap::create(BP, $_SERVER);

 $objectManager = $bootstrap->getObjectManager();
 $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
 $connection = $resource->getConnection();
 $state = $objectManager->get('Magento\Framework\App\State');
 $state->setAreaCode('frontend');

 $request = new SoapClient("https://your_domain/soap/?wsdl&services=integrationAdminTokenServiceV1", array("soap_version" => SOAP_1_2));
 // changes your store url.
 $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"admin", "password"=>"admin@123"));

 $request = new SoapClient(
     'https://your_domain/soap/default?wsdl&services=catalogInventoryStockRegistryV1',
     array(
  'soap_version' => SOAP_1_2,
  'stream_context' => stream_context_create(array(
      'http'=> array('header' => 'Authorization: Bearer '.$token->result)
  ))
     )
 );
 
 $qtyData = [
     'qty' => 1000,
     'isInStock' => 1,
     'isQtyDecimal' => 0,
     'showDefaultNotificationMessage' => 0,
     'useConfigMinQty' => 0,
     'minQty' => 2,
     'useConfigMinSaleQty' => 1,
     'minSaleQty' => 1,
     'useConfigMaxSaleQty' => 0,
     'maxSaleQty' => 10,
     'useConfigBackorders'  => 0,
     'backorders' => 1,
     'useConfigNotifyStockQty' => 0,
     'notifyStockQty' => 10,
     'useConfigQtyIncrements' => 1,
     'qtyIncrements' => 1,
     'useConfigEnableQtyInc' => 1,
     'enableQtyIncrements' => 1,
     'useConfigManageStock' => 1,
     'manageStock' => 1,
     'lowStockDate' => 1,
     'isDecimalDivided' => 1,
     'stockStatusChangedAuto' => 1
 ];

 $response = $request->catalogInventoryStockRegistryV1UpdateStockItemBySku(['productSku'=> 'Simple Product', 'stockItem' => $qtyData]);
 
 echo "<pre>";
 print_r($response);
 echo "</pre>";

}catch (\Exception $e){
    echo $e->getMessage() . " \n";
}

Conclusion:

Hence, using the above method, you can easily update Specific Product Quantities using SOAP API in Magento 2. Share the article with your friends and stay updated with us for more.

Happy Coding!

Click to rate this post!
[Total: 1 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

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

8 hours ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

1 day ago

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

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

1 day ago

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

1 week ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

1 week ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

2 weeks ago