How to Set Up And Use Magento 2 SOAP API

How to Set Up And Use Magento 2 SOAP API

Did you know that Magento powers over 250,000 online stores globally? Magento 2 SOAP API offers a powerful method for integrating your store with external apps. This tutorial outlines a clear, step-by-step process for setting up and using the Magento 2 SOAP API. It covers accessing API endpoints, establishing user roles, and implementing authentication.

Key Takeaways

  • Discover how to integrate external applications using the Magento 2 SOAP API.

  • Learn the process to access and configure API endpoints. Gain a thorough understanding of Magento's web API ecosystem.

  • Understand how to set up user roles and manage authentication securely.

  • Gain insights on enhancing your store’s operations through effective API use.

What is SOAP API in Magento 2?

SOAP API (Simple Object Access Protocol) is a web service in Magento 2. SOAP API allows external applications to interact securely with the Magento platform. The API relies on the WSDL (Web Services Description Language) to define available operations.


Developers use the SOAP API for various tasks. This API allows external applications to interact smoothly with Magento's core functionalities. These include retrieving product details and updating order statuses by making requests to a specific URL.


The SOAP API in Magento 2 facilitates the integration of Magento with other systems. It uses standard web protocols, making it versatile for developers familiar with PHP, Magento's programming language.

Benefits of Using Magento 2 SOAP API

1. Standardized Communication

The SOAP API in Magento 2 uses the Web Services Description Language (WSDL). It defines and exchanges structured data. Standardization allows reliable interaction with Magento across different technologies.

2. Secure Data Exchange

The API uses strong encryption and authentication methods, including SSL and OAuth access tokens. These ensure secure data exchange between Magento and external systems.

3. Comprehensive Integration

By using Magento SOAP API, developers can create web services that deeply interact with Magento entities. It showcases how SOAP provides a strong foundation for API interactions. It is beneficial for integrating Magento with third-party systems, enhancing the store's functionality.

4. Complex Operations

Magento 2 supports both SOAP and REST APIs. SOAP is typically used for complex transactions and secure communication. SOAP is well-suited for handling complex data structures and operations. It can manage detailed service contracts, which are part of the WSDL file. Each service contract is represented as a separate service, allowing for precise control over the APIs.

5. Flexibility

Developers can leverage SOAP API endpoint in Magento 2. They do this by navigating to the API tab and selecting the desired Magento resources. This flexibility allows for tailored solutions that meet specific business needs.

Understanding Magento SOAP APIs for Developers

I. Interoperability

1. Standardization: The SOAP API adheres to established web service protocols. It allows for easier integration across various platforms. It's essential for developers working in diverse technological environments.


2. Integration: Useful for connecting Magento to external systems such as

  • Salesforce (CRM)

  • PayPal (payment gateway)

  • SAP (ERP solutions)

For example, a business using Magento can enhance CRM by integrating with Salesforce. It can also streamline payment processing by integrating with PayPal.

II. Complex Data Handling

1. Data Exchange: Allows for the definition and structured exchange of complex data. This flexibility is important for synchronizing various data types across systems. Examples include,


2. Operation Support: The SOAP API supports detailed operations, essential for managing intricate datasets. A retailer might use CRUD operations for various tasks:

  • Update inventory levels

  • Manage product descriptions

  • Process customer orders

This functionality ensures accurate and up-to-date data across platforms.

Access SOAP API Endpoint in Magento 2

Each WSDL file is tailored to different services required by various clients. Every service interface, part of a service contract, is represented as a separate service in the WSDL file.

Step 1: Specifying Services in the WSDL URL

You need to specify the desired services in the WSDL endpoint URL to use different services through SOAP API. Below are examples for both single and multiple service access:

Service Access Type Service Names WSDL URL Interface Names
Single Service Customer http://magentohost/soap/all?wsdl&services=customerCustomerRepositoryV1 \Magento\Customer\Api\Data\CustomerInterface
Multiple Services Customer, Catalog Product http://magentohost/soap/custom_store?wsdl&services=customerCustomerRepositoryV1,catalogProductRepositoryV1 \Magento\Customer\Api\Data\CustomerInterface, \Magento\Catalog\Api\Data\ProductInterface

Step 2: Formatting the WSDL URL

Use the following pattern to format your WSDL URL: http://<host>/soap/<optional_store_code>?wsdl&services=<service_name_1>,<service_name_2>


Note: Always specify each service version in the endpoint URL.

5 Steps to Create a New SOAP API User

Step 1: Access the Admin Panel

Log into the Magento 2 Admin Panel.

Step 2: Navigate to User Roles

Navigate to User Roles

  1. Go to System > User Roles.

  2. Click the Add New Role button.

Step 3: Define the Role

Define the Role

  1. Enter a name for the role.

  2. In the Your Password field, enter your current Magento 2 Admin password.

Step 4: Set Role Resources

Set Role Resources

  1. Click on Role Resources on the left-hand side.

  2. Under Resource Access, select the resources needed for your web service.

Step 5: Save the Role

Click the Save Role button.

How to Create Web Service User in Magento 2?

Step 1: Add a New User

Add a New User

  1. Go to System > All Users.

  2. Click on Add New User.

Step 2: Enter User Details

Enter User Details

Fill in the User Name, First and Last Name, Email, and Password.

Step 3: Assign User to Role

Assign User to Role

  1. On the left-hand side, click on User Role.

  2. Select the newly created role.

  3. Click the Save User button to complete the setup.

Magento 2 API Authentication Request Types

1. Token Authentication

Purpose: Specifically designed for mobile applications.

Mechanism: Generates a unique token that mobile apps use to authenticate API calls. This token acts as a secure key for accessing Magento's resources.

Procedure:

Step 1: Send login credentials via an API call to receive a token.

Step 2: Use this token in subsequent API requests to authenticate.

2. OAuth Authentication

Purpose: Best suited for third-party web services that need extended access to Magento APIs. Protected SOAP resources can be accessed using bearer tokens (OAuth access tokens) over HTTP.

Mechanism: Utilizes the OAuth standard to ensure secure delegated access. It allows third-party services to interact with Magento on behalf of a user while keeping user credentials hidden.

Procedure:

Step 1: Obtain a request token from Magento.

Step 2: Have the user authorize the request token.

Step 3: Exchange the authorized request token for an access token.

Step 4: Use the access token to make API calls.

3. Session Authentication

Purpose: Ideal for interactions directly through Magento's web interface, typically in a browser.

Mechanism: Uses the user's current logged-in session and cookies to authenticate API calls made through the browser.

Procedure:

Step 1: Log into Magento’s web interface.

Step 2: Use the generated session from the login to authenticate API calls.

Note: For the Magento 2 SOAP API, token-based authentication should be implemented through the creation of an integration.

7 Steps to Create the SOAP API Integration

Step 1: Access the Admin Panel

Log in to the Magento 2 Admin Panel.

Step 2: Create New Integration

Create New Integration

  1. Go to System > Integrations.

  2. Click on Add New Integration.

Step 3: Enter Integration Details

Enter Integration Details

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

Step 4: Configure API Access

Configure API Access

  1. Go to the API tab within the integration settings.

  2. Select the Magento resources to which you want to allow access. You can choose either all resources or a custom list.

Step 5: Save and Activate Integration

Save and Activate Integration

  1. Click the Save button to save and update the integration information.

  2. Go back to the integration listing page and click the Activate link next to the newly created integration.

Step 6: Authorize and Retrieve Tokens

Authorize and Retrieve Tokens

  1. In the dialog box that appears, click on Allow.

  2. Another dialog box will open, displaying the generated tokens and keys for the integration.

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

Copy Access Token, Access Token Secret, Consumer Key, and Consumer Secret values

Step 7: Finalize the Setup

Finalize the Setup

Click Done to save the token and check that the integration status is Active.

FAQs

1. What is Magento 2 SOAP API?

Magento 2 SOAP API is a web service protocol that allows external applications to communicate with the Magento 2 store. It provides a robust and secure way to interact with the Magento system using SOAP services.


2. How can I use Magento 2 SOAP API to access resources?

You can use SOAP API to access various resources in Magento 2, such as, products, customers and orders. By making SOAP requests to the API endpoints, you can retrieve, create, update, and delete data within your Magento store.


3. What are the main differences between REST API and SOAP API in Magento 2?

REST API in Magento 2 is more lightweight and uses standard HTTP methods for communication. SOAP API is more structured and relies on XML messaging format. REST API is preferred for simple integrations, while SOAP API is suitable for complex and enterprise-level integrations.


4. How do I set up Magento 2 SOAP API services?

To set up Magento 2 SOAP API services, you need to enable the SOAP Web services configuration in your Magento backend. You also need to generate API credentials and whitelist the IP addresses that can access the API endpoints.


5. What is a WSDL endpoint in Magento 2 SOAP API?

WSDL endpoint in Magento 2 SOAP API provides a detailed description of the available web services. It includes the operations, data types, and endpoints supported by the API.


6. How can developers create custom web services using Magento 2 SOAP API?

Developers can create custom web services in Magento 2 using SOAP Magento API. They do this by writing custom modules that expose the desired functionalities as SOAP service endpoints. It allows for tailored integration with external applications.


7. What are Magento web APIs, and how do they relate to SOAP services?

Magento web APIs, including both REST and SOAP, are a set of interfaces. They allow different systems to communicate with Magento, enhancing connectivity and functionality. SOAP API is one of the available web APIs in Magento that provides a standardized way to interact with the platform.

CTA

Summary

The Magento 2 SOAP API is a strict, secure web service. It enables secure interactions between external applications and the Magento platform. It utilizes the Web Services Description Language (WSDL) to define operational protocols. To recap, here's a brief overview of the main takeaways,

  1. It highlights the standardization, security, and integration capabilities of the Magento 2 SOAP API.

  2. It outlines the steps to access the SOAP API endpoint and how to create and manage users and roles.

  3. It describes the different authentication methods available, including Token, OAuth, and Session, for secure API interactions.

  4. It gives details on the steps to initiate and manage API integrations. These steps include selecting resources and managing authentication tokens.

Explore Magento hosting services for smooth operation when integrating SOAP API into your store.

Andrea Oriane
Andrea Oriane
Technical Writer

Andrea specializes in creating informative content for Magento. With extensive e-commerce knowledge and understanding of Magento functionalities, she crafts articles for a wide range of audience.


Get the fastest Magento Hosting! Get Started