Magento is a robust ecommerce platform for scalable businesses. It has made it easier for developers to directly manage resources such as customers, categories, products, and sales orders through APIs. Its APIs also allow the developers to control shopping carts and inventory.
Magento has two major Web APIs, including REST and SOAP APIs. One of the prominent APIs offered by Magento 2 is the SOAP API, which stands for Simple Object Access Protocol.
This article will focus on Magento 2 SOAP API integration, functionalities, endpoint access, fundamental aspects of SOAP API, and many others. Magento 2 SOAP API empowers you to seamlessly connect your store with external systems, opening doors to endless possibilities for growth and optimization.
- An Overview of SOAP API in Magento 2
- Benefits of Using SOAP API With Magento 2
- Why Is SOAP API Useful for Developers?
- Compare SOAP API vs Rest API
- Access SOAP API Endpoint in Magento 2
- Create a New SOAP API User
- Create Web Service User in Magento 2
- Magento 2 API Authentication Request Types
- Use SOAP API Service in Magento 2
An Overview of SOAP API in Magento 2
Simple Object Access Protocol (SOAP) Application Programming Interface (API) is a highly strict, secure, structured protocol used by Magento 2 to allow communication between different software systems or applications. It provides standardized communication between systems that encodes data in XML.
In Magento 2, SOAP API allows external applications to communicate with Magento 2 system, such as products, customers, and other information. By using SOAP API, developers can integrate third-party applications such as payment gateway, CRM, shipping services, and others with Magento 2.
Among the important aspect of SOAP API in Magento 2 is the flexible solution to integrate and automate various tasks.
Experience the Cloudways Magento 2 Demo Store – No tech skills needed!
Experience a fully functional Magento 2 store built on top of renowned Cloudways hosting to deliver the fastest speeds.
Benefits of Using Magento 2 SOAP API
There are several benefits of using SOAP API in Magento 2.
Language Independence: The SOAP API is based on XML and HTTP protocols, which are platform-independent. This means that you can use any programming language or platform to access the Magento 2 store’s functionality.
Security: SOAP provides a robust, secure way to exchange data through encryption and authentication mechanisms such as SSL.
Extensibility: SOAP API in Magento 2 is extensible with other technologies and systems, which makes it easier to handle large amounts of data, such as products.
Functionality: Through SOAP API, developers can access various functionalities in Magento 2, such as managing customers, ordering, building custom applications, and more.
Although there are many other benefits of SOAP API, it entirely depends on the situation and use cases to choose the protocol.
Why Is SOAP API Useful for Developers?
First and foremost, SOAP API ensures a high level of interoperability. It follows a set of standards that allow developers to create web services that can be easily consumed by various platforms and programming languages.
This makes it an excellent choice for integrating Magento with third-party systems, such as CRM software, payment gateways, or ERP solutions. By leveraging SOAP API, developers can establish reliable and consistent communication channels between different applications, regardless of their technologies.
Another advantage of SOAP API is its extensive support for complex data structures and operations. It allows developers to define and exchange structured data in a highly flexible and versatile manner.
With SOAP, you can work with multiple data types, including simple values, arrays, and custom objects. This capability is particularly valuable when working with large and intricate datasets or performing sophisticated operations like CRUD (Create, Read, Update, Delete) actions on Magento entities.
Compare SOAP API vs Rest API
Here’s a comparison table highlighting the key differences between SOAP API and REST API.
|SOAP API||REST API|
|SOAP (Simple Object Access Protocol) is a messaging protocol that uses XML for communication.||REST (Representational State Transfer) is an architectural style that uses simple HTTP protocols like GET, POST, PUT, and DELETE.|
|SOAP API supports multiple data formats, including XML, JSON, and more.||REST API primarily uses JSON format for data exchange, although it can also support other formats.|
|SOAP API is more rigid and requires a predefined contract (WSDL) that defines the structure and operations of the web service.||REST API is flexible and does not rely on a predefined contract, allowing for a more dynamic and lightweight implementation.|
|SOAP API is widely used for integrating complex and enterprise-level systems due to its support for features like security, transactions, and reliable messaging.||REST API is often preferred for simpler and more lightweight applications, especially in web and mobile environments.|
|SOAP API requires more bandwidth and is usually slower than REST API due to its extensive use of XML and complex message formats.||REST API is lightweight and performs quickly and efficiently, especially when working with limited resources or mobile networks.|
|SOAP API has built-in support for advanced security standards like WS-Security, making it suitable for applications that require strict security measures.||REST API provides security through standard HTTPS protocols and can leverage additional security measures like API keys, OAuth, or JSON Web Tokens (JWT).|
|SOAP API offers better support for error handling and includes standardized fault messages for easier debugging and troubleshooting.||REST API relies on HTTP status codes and custom error messages for error handling, which can be simpler to understand and implement.|
Access SOAP API Endpoint in Magento 2
SOAP API uses the Web Service Description Language (WSDL) file format for requesting services. A WSDL file is used for different clients who may use different services and therefore use different WSDLs.
Each service interface part of a service contract is represented as a separate service in the WSDL. To consume several services, specify them in the WSDL endpoint URL.
|Service Name||WSDL URL||Interface Name|
|customer, catalogProduct||http://magentohost/soap/custom_store?wsdl&services=customerCustomerRepositoryV1,catalogProductRepositoryV1||\Magento\Customer\Api\Data\CustomerInterface, \Magento\Catalog\Api\Data\ProductInterface|
The WSDL URL follows the following pattern.
You must specify each service version in the endpoint URL.
Get a List of SOAP Services
If you want an overview of all the available Web Services, use the following URL format to get a list of all SOAP Services:
Response: You will get the response below.
<response> ….. <storeStoreRepositoryV1> <wsdl_endpoint>http://<host>/soap/all?wsdl&services=storeStoreRepositoryV1</wsdl_endpoint> </storeStoreRepositoryV1> …. </response>
Create a New SOAP API User
To create a web service role in Magento 2, follow these steps.
- Log into the Magento 2 Admin Panel.
- Go to System → User Roles and click the Add New Role button.
- Enter the Role name, and in the Your Password field, enter the current password of your Magento 2 Admin.
- On the left-hand side, click Role Resources. Under Resource Access, select only what is required for your web service.
5. Once done, hit the Save Role.
Create Web Service User in Magento 2
Create a new user for the newly created role by following these steps:
- Navigate to System → All Users, then click Add New User.
- Enter the required information, including User Name, First and Last Name, Email, and Password.
3. On the left-hand side, click User Role, and then select the newly created role. Once done, click the Save User button.
Once after creating the role, let’s create the integration to authenticate the SOAP API.
Magento 2 API Authentication Request Types
An integration enables third-party services to call the Magento web APIs. Magento 2 API provides three authentication types based on the use case.
- Token authentication (Mobile app Authentication)
- OAuth authentication (Third-party authentication)
- Session authentication (Browser-based Authentication)
For the Magento 2 SOAP API, we are following the token-based authentication request type by creating an integration.
Create the SOAP API Integration
To create the integrations token, follow these steps.
- Log in to the Magento 2 Admin Panel.
- Go to System → Integrations and click Add New Integration.
3. Fill in the required fields, such as Name, Email, and current logged-in user password.
- Go to the API tab and select the Magento resources, to which you want to allow access for the integration. You can choose all resources or opt for a custom list.
5. Click the Save button to save and update the information.
- Go to the integration’s listing page, and click the Activate link for the newly created integration.
- In the dialog box, click on Allow, and a dialog box will be opened, which displays the generated tokens and keys for the Integration created.
- Copy the Access Token, Access Token Secret, Consumer Key, and Consumer Secret values for later use.
- Click Done to save the token and check the integration in Active.
Once the tokens are generated, we will use these access tokens in the SOAP API calls, which are made on behalf of the integration.
Use SOAP API Service in Magento 2
You need the following endpoint to call the Magento 2 SOAP API.
URL For Magento SOAP API: http://yourdomain.com/soap/all?wsdl_list=1 or
With any method:
As an example below, the PHP code snippet shows how to call the catalogProductList method of the SOAP API in Magento 2.
<?php // Initialize the SOAP client $client = new SoapClient('http://<magento_host>/soap/v2?wsdl=1'); // Set the API credentials $token = $client->login(['username' => 'api_username', 'apiKey' => 'api_key']); // Call the catalogProductList method $product_list = $client->catalogProductList($token, ['type_id' => 'simple']); // Print the product list print_r($product_list); // End the session $client->endSession($token); ?>
In the above code, the SOAP client is created using the endpoint and set the API credentials using the login method.
SOAP API in Magento 2 empowers developers to create powerful integrations, enhance data exchange, and prioritize security. You can unlock new possibilities for your Magento stores and build a scalable platform that meets your business’s and customers’ evolving needs.
Once you have your SOAP API up and running, you can leverage its power to seamlessly integrate Magento with other third-party applications, such as CRM software, payment gateways, or inventory management systems.
Jyotishina is the Magento Community Expert at Cloudways and has 4 years of experience in web development. She has worked on e-commerce sites since the turn of the millennium and was working with Magento before version 1 was released. She loves to travel and explore new ideas whenever she finds time. Get in touch with her at [email protected].