This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Join our live AMA on the Future of Page Builders with Brizy's CEO! Register Now →

How to Create and Use SOAP API in Magento 2 (A Developer-Friendly Guide)

Updated on May 23, 2023

7 Min Read
Magento 2 SOAP API

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

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 http://magentohost/soap/all?wsdl&services=customerCustomerRepositoryV1 \Magento\Customer\Api\Data\CustomerInterface
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.

http://<host>/soap/<optional_store_code>?wsdl&services=<service_name_1>,<service_name_2>

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:

http://<host>/soap/all?wsdl_list=1

Request: https://magento-761105-3369153.cloudwaysapps.com/soap/all?wsdl_list=1

Response: You will get the response below.

<response>

…..

    <storeStoreRepositoryV1>            <wsdl_endpoint>http://<host>/soap/all?wsdl&services=storeStoreRepositoryV1</wsdl_endpoint>

    </storeStoreRepositoryV1>

….

   </response>

soap-all-list

Create a New SOAP API User

To create a web service role in Magento 2, follow these steps.

  1. Log into the Magento 2 Admin Panel.
  2. Go to System → User Roles and click the Add New Role button.

Newrole

  1. Enter the Role name, and in the Your Password field, enter the current password of your Magento 2 Admin.

SaveNameRole

  1. On the left-hand side, click Role Resources. Under Resource Access, select only what is required for your web service.

RoleResources

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:

  1. Navigate to System → All Users, then click Add New User.

AddNewUser

  1. Enter the required information, including User Name, First and Last Name, Email, and Password.

userfill-details

3. On the left-hand side, click User Role, and then select the newly created role. Once done, click the Save User button.

SaveNewUser

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.

  1. Token authentication (Mobile app Authentication)
  2. OAuth authentication  (Third-party authentication)
  3. 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.

  1. Log in to the Magento 2 Admin Panel.
  2. Go to System → Integrations and click Add New Integration.

soap-integration

3. Fill in the required fields, such as Name, Email, and current logged-in user password.

integerationSave

  1. 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.

soap-api-resources

5. Click the Save button to save and update the information.

show-integeration

  1. Go to the integration’s listing page, and click the Activate link for the newly created integration.
  2. 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.

Activate-integration

  1. Copy the Access Token, Access Token Secret, Consumer Key, and Consumer Secret values for later use.

save-tokens

  1. Click Done to save the token and check the integration in Active.

active-integration

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:

http://<magento_host>/soap/default?wsdl&services=catalogProductRepository

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.

Summary

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.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Jyotishna Kumari

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].

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now