How to create Magento 2 Admin token.

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

Without an Access token, you can’t communicate with Magento 2. For Create an 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 the username and password in the request body of the Magento backend to generate the Access token.

$url = "";
$token_url = $url."/V1/integration/admin/token";
$username = "admin";
$password = "admin123";

//Authentication rest API magento2, For get access token
$ch = curl_init();
$data = array("username" => $username, "password" => $password);
$data_string = json_encode($data);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$token = curl_exec($ch);
$accessToken = json_decode($token);
echo $accessToken;

After successfully call with Magento 2, You can get a 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.

Postman Screen to generate Admin Token for the Magento 2,

Spread the love

Related Posts

Leave A Comment

This error message is only visible to WordPress admins

Error: No connected account.

Please go to the Instagram Feed settings page to connect an account.