How to create access token for Magento 2 Rest api programmatically?

For Access Magento 2 REST API, you need to first generate an access token. Access token used for synchronization with Magento to another third-party platform.

Without Access token, you can’t communicate with Magento 2. For Create access token you need to call POST action with Request payload. Your request URL will be rest/V1/integration/admin/token append to your site URL.

Pass Username and password in request body of Magento backend to generate the Access token.

After successfully call with Magento 2, You can get response as a string with Access Token. You can use access token with any Magento 2 REST API call with “Bearer $accessToken


You can Use the token in a Web API request as below,
Authorization: Bearer <access token>
Where Replace <access token> token with your actual access token.

3 Replies to “How to create access token for Magento 2 Rest api programmatically?”

  1. How do we get refresh token once its about to expire? By default this is set to 1 hour and suppose if the user who is browsing on the site stays more than a hour this will kick them out. So am looking for refresh token functionality in Magento 2 without adjusting the token expiry time.

Leave a Reply