Magento web API framework is used to communicate third party services with the Magento System. In Magento 2, the web API allows exposure of the module API (service contact) through the WEB API. It extends the  functionality from Magento 1 API.

Each repository and API are available through web API. It follows strict definition for all the classes, parameters and return values.

We have to declare a URL in webapi.xml and need to specify the required interfaces (available services) and methods for the APIs.

Implementing SOAP & REST API in Magento 2


We have two types of protocols to make a repository available through web API

  • SOAP API (Simple Object Access Protocol)
  • REST API (Representational State Transfer) 

It is easier to implement REST API because it is less strict than SOAP API. The implementation is taken from the di.xml file, which calls the method.

The diagram below shows the process in detail.

D1

 Example webapi.xml 

1D1a

Router contains the URL and a method (GET, POST, and DELETE).

Service defines the interface class and the method for handling.

Resources defines the list of users (ACL Resource) for accessing the web API.

Three types of resources are available in Magento 2 for the web API

  1. Self – available for customer data
  2. Anonymous – available for all
  3. Magento ACL  – Admin user (this requires permissions)

Web API Authentication 

There are three types of Authentication

  1. OAuth
  2. Token Based
  3. Session Based 

For Token based authentication, we need to create an Admin user with specific permission.

Integration of Web API

To create an integration, click System > Integration > Add New Integration. Be sure to restrict the resources that the integration can access.

Below are the screen shots of the procedure for new Integration and Activation.

D1a

D2a

D3a

D4a

SOAP WSDL URL

WSDL is generated automatically for both system and custom services.

WSDL Structure

http://You Magento Host / soap?wsdl&services=  [Defined List of services]

Example:

D5a

 REST Authentication

This supports token based authentication.

URL for accessing through REST

http://{Your Magento Repo}/rest/V1/ConsumerRepo?{Arguments}

Example:

curl  -X GET “http://127.0.0.1/m2/rest/V1/ConsumerRepo” –H  “Authentication : Bearer_Token-“

One of the many goals of Magento 2 is  to improve on the web APIs. For more information on Magento 2 web API , please go through the documentation below…

http://devdocs.magento.com/guides/v2.0/get-started/bk-get-started-api.html

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

5 Comments on "Implementing SOAP & REST API in Magento 2"


Guest
amith
1 year 5 months ago

Hi i need to implement shipyaari api in to magento 2.1.3 how can i do this with a module

Guest
Arun
2 years 1 month ago

Hi, I am stuck with Oauth token request process it says ‘oauth_problem=Consumer+key+has+expired’.
Can you tell me what is causing this?

Guest
Mykhailo
2 years 4 months ago

I have a separate application. I need to create customer, cart, items and place order. Better to use a “Token Based” or “OAuth”?

admin
Admin
2 years 4 months ago

Hi,

Can you please send us more details on your query? Thanks

Guest
Arun
2 years 5 months ago

how do we create a new Product in Catalog using Magento V2.0 SOAP API.