Magento Tutorials

Understanding Magento SOAP API

What is SOAP API?

SOAP (Simple Object Access Protocol) is a protocol for transmitting structured information in computer networks. It uses XML for its message format, which allows computers running on different platforms (Windows and Linux, e.g.) to communicate to each other, as long as those computers support web service protocol (HTTP for example).

Magento SOAP API

Magento 1 and Magento 2 are both SOAP-included.

Magento 1

API format in Magento 1:

http://magento.url/api/soap/?wsdl

XML result:

magento 1 api

From Magento version 1.3, SOAP API is updated into version 2 to better support Java and .NET. Hence, URL format is changed into:

http://magento.url/api/v2_soap?wsdl=1
magento 1.3 api

Magento 2

API format in Magento 2:

http://magento2.url/soap?wsdl_list=1
magento 2 api

Create User and Role to use API

Create Role

  1. In your Magento backend, go to System > Web Services > SOAP/XML-RPC – Roles.
  2. Click Add New Role.
  3. Under Role Info, enter a name for this role. You may need to enter current admin password to continue.
  4. Under Role Resources, choose which resources this role can access to.

Create User

  1. In your Magento backend, go to System > Web Services > SOAP/XML-RPC – Users.
  2. Click Add New User.
  3. Under User Info, enter the necessary information.
  4. Under User Role, select a role for this user.

Example: Using SOAP API in PHP to get category tree

SOAP v1:

$client = new SoapClient('http://localhost.com/magento19/api/soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'catalog_category.info', '5');
var_dump($result);

SOAP v2:

$proxy = new SoapClient('http://localhost.com/magento19/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey'); // TODO : change login and pwd if necessary
$result = $proxy->catalogCategoryInfo($sessionId, '5');
var_dump($result);
soap v2 api

You can refer to APIs in this Magento document:  http://devdocs.magento.com/guides/m1x/api/soap-api-index.html


Read more:
How to Use AJAX Requests in Magento
Magento API for Android

Dom

A knowledge craver who always strive to be wiser everyday.

Subscribe
Notify of
guest

5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jerome Nicholas
Jerome Nicholas
4 years ago

An Error occurred while handling another error:
exception ‘ReflectionException’ with message ‘Method SoapClient::login() does not exist’ in

Omar
Omar
2 years ago

Hello Dom thanks for informative article. Just a problem like you print_r and debug the object. How can i see raw xml on browser from this script? please guide me

Osh University
2 months ago

As a vital component of the  kyrgyz national university  network, Osh University is a trusted choice for higher education, providing students with a supportive environment and a rich academic experience.

Shalamar Hospital
2 months ago

Shalamar Hospital is your premier choice for urological care, boasting the  best urologist in Pakistan . Trust us for expert treatments and exceptional patient care.

Jewel Galore
2 months ago

Elevate your fashion game with Jewel Galore’s  bridal jewellery set. These unique pieces add a touch of luxury and individuality to your look, making a bold statement.