Tips: Retrieving the Product Quantity from the Magento API

Getting the product stock quantity in Magento is a bit tricky as you can’t get it from catalog_product.info API call.

You need to use cataloginventory_stock_item.list API call. It has only one argument:
  • array products – list of product IDs or SKUs

 

The array of products here means that you can request multiple product IDs in a request. Here is a snippet of what the product quantity soap request looks like:

<sessionId xsi:type=”xsd:string”>59bc9730d567c9351e2507acb1d97bd0</sessionId>
<products xsi:type=”urn:ArrayOfString” soapenc:arrayType=”xsd:string[]”>

<id>16</id>

<id>17</id>
<id>18</id>
</products>
And the result return:
<item xsi:type=”ns1:catalogInventoryStockItemEntity”>
<product_id xsi:type=”xsd:string”>16</product_id>
<sku xsi:type=”xsd:string”>n2610</sku>
<qty xsi:type=”xsd:string”>996.0000</qty>
<is_in_stock xsi:type=”xsd:string”>1</is_in_stock>
</item>
<item xsi:type=”ns1:catalogInventoryStockItemEntity”>
<product_id xsi:type=”xsd:string”>17</product_id>
<sku xsi:type=”xsd:string”>bb8100</sku>
<qty xsi:type=”xsd:string”>797.0000</qty>
<is_in_stock xsi:type=”xsd:string”>1</is_in_stock>
</item>
<item xsi:type=”ns1:catalogInventoryStockItemEntity”>
<product_id xsi:type=”xsd:string”>18</product_id>
<sku xsi:type=”xsd:string”>sw810i</sku>
<qty xsi:type=”xsd:string”>989.0000</qty>
<is_in_stock xsi:type=”xsd:string”>1</is_in_stock>
</item>