Skip to content

Step 1. Get the admin token [Web API Tutorial]

Ievgen Shakhsuvarov edited this page Jul 16, 2019 · 5 revisions

Most REST calls to Magento require an authorization token. The token allows Magento to verify that the caller is authorized to access a system resource. To get a token, you must specify the user’s username and password in the payload.

By default, an admin token is valid for 4 hours. To change this value, log in to Admin and go to Configuration > Services > OAuth > Access Token Expiration.

See Token-based authentication for more information abo ut authorization tokens.

Endpoint
POST http://<host>/rest/default/V1/integration/admin/token

Headers
Content-Type application/json
Authorization: Bearer <admin_token>

Payload

{
"username": "<admin username>",
"password": "<admin password>"
}

Response
Magento returns the admin’s access token.
5r8cvmpr11j6gmau8990rcj2qk7unh8i

This token must be specified in the authorization header of every call that requires admin permissions. This token is not displayed in Admin.

Complete cURL request sample

endpoint="http://<host>/rest"
username="<admin username>"
password="<admin password>"
admin_token=$(curl -X POST "$endpoint/V1/integration/admin/token" \
 -H "Content-Type: application/json" \
 -d '{"username":"'"$username"'","password":"'"$password"'"}') && echo $admin_token && admin_token=$(echo $admin_token | tr -d '"')

◀️ Previous Step 📖 Table of Contents Next Step ▶️

MSI Documentation:

  1. Technical Vision. Catalog Inventory
  2. Installation Guide
  3. List of Inventory APIs and their legacy analogs
  4. MSI Roadmap
  5. Known Issues in Order Lifecycle
  6. MSI User Guide
  7. DevDocs Documentation
  8. User Stories
  9. User Scenarios:
  10. Technical Designs:
  11. Admin UI
  12. MFTF Extension Tests
  13. Weekly MSI Demos
  14. Tutorials
Clone this wiki locally