search
top

Magento SOAP API

Hello All,

While working in Magento, some times need arises to use Magento API.

Magento Core API supports both SOAP and XML RPC protocols. The API is permission based and allows access to the Customer, Catalog and Order modules of Magento. You can get the information here
Magento Core API

I am listing here the basic way to use SOAP API.

SOAP

SOAP (Simple Object Access Protocol) adapter is default adapter for webservices. If you want to connect to Magento SOAP webservices you should load WSDL from this link (http://youmagentohost/api/?wsdl or http://youmagentohost/api/soap/?wsdl) in your SoapClient

The System → Web Services → Users option allows you to create authorized users for web services APIs

Bind the new user to a predefined role. A role for the API must be created in System → Web Services → Roles before it can be assigned here.

I am writing here an example to get catalog data using SOAP API

<?php

$site_path = "http://youmagentohost/";
try {
	$proxy = new SoapClient($site_path.'api/soap/?wsdl=1');
	$sessionId = $proxy->login('apiUser', 'apiKey');  
}catch (SoapFault $e)
{
	$msg = "Could not connect to the site".$e->getMessage();
	echo $msg."<br/>";	
}

//getting all categories inside magento
//start
$allCategories = $proxy->call($sessionId, 'category.tree',2); // Get all subcategories inside root category.
$cat_name = array();
	
foreach ($allCategories['children'] as $k => $v)
{		
	echo 'Category id ->'.$v['category_id'];
	echo 'Category name ->'.$v['name']; 	
}	
//end

//get product sku array
//start
$products = $proxy->call($sessionId, 'product.list');   
$sku_arr = array();
foreach ($products as $k => $v)
{
	$sku_arr[] = $v['sku'];
}
//end

$proxy->endSession($sessionId); //end session
?>

I hope this is helpful.

Further reading: 28-Feb-2012 – Category and Product SOAP API in Magento

3 Responses to “Magento SOAP API”

  1. meena says:

    I run above code on server , but it give following error:-

    Could not connect to the siteSOAP-ERROR: Parsing WSDL

    any reply is greatly appreicated .
    Thanks

    • Pragnesh says:

      Are you using SOAP version 2 ? if yes, In SOAP V2, there are separate methods for each action, instead of using methods call and multiCall. Please refer this for the difference Magento API

  2. lazyvlad says:

    yeah it’s helpful indeed

Leave a Reply

top