Sharing some useful tips, solutions and notes for Geeks.

Wednesday, August 28, 2019

Magento postman api - getting authetication tokens - part 2

In Magento2, there are mainly two type of authentications: Token Based Authentication and Oauth Based Authentication. I am mainly going through Token Based Authentication in this tutorials. Oauth based with cover later.

Token based is mainly splitted into admin and customer. Whenever we need to connect to Magento 2 api, we need access tokens generated. This access tokens are unique one which we get from Magento when we call below together with username and password.

Get an admin token : POST /V1/integration/admin/token
Get a customer token : POST /V1/integration/customer/token

Also you must know "username" and "password" as well which is used to get access token.

Now open the postman application. Its better to start with collections in postman as it helps in retrieving the data anywhere - ie in the application we installed in system, in the online system etc ie its globally accessible.
Inside a collection, click + symbol to create a new instance.

once clicked, you can see a set of fields to manage.

In the request type, we need to set as POST since we are going to request for a token from the server. Now in the request URL please enter <domainname>/index.php/rest/V1/integration/admin/token.
We need to pass username and password as parameters to this. For this you can have three options:
1. Globally store details in Manage Environment
2. Put as arguement in the above URL as ?username=xxxxx&password=xxxxx
3. Add inside the query parameter section we have.

Once we add and click "Send" we will get the unique token which we can use for data manipulation.

Voila, thus we get the access token. In the next chapter, we can go through how we need to make use of this token.

No comments: