# Getting an Access Token

> Request a token with your service account, send it on every call, and request a new one when it expires after an hour.

Product: RAZE Developer Portal
Source: https://getaraze.com/tools/api-access-token
All guides: https://getaraze.com/tools

## Quick Reference

- Call Obtain access token with your service account username and password.
- Send it as a URL-encoded form with the password grant type.
- Put the token in the Authorization header as a Bearer token on every other call.
- Request a new token every hour.

## Before You Start

- You have the service account username and password for the environment you're calling.
- You're signed in to the Developer Portal.

## Step 1: Request the Token

**Call Obtain access token.** In Documentation, open Auth and select Obtain access token. Send your service account username and password with the OAuth 2.0 password grant, as a URL-encoded form.

**Read the response.** A successful call returns the access token, its type (bearer) and how many seconds it lasts. A wrong username or password returns an invalid grant error.

## Step 2: Send It on Every Call

**Add the Authorization header.** Every call except the token request carries the token as a Bearer token in the Authorization header.

## Step 3: Renew It Every Hour

**Request a new token when it expires.** Tokens last one hour (3,600 seconds). Request a new one before it runs out, or as soon as a call fails because the token expired.

## Tips

**DO**
- Reuse one token for all calls until it expires.
- Request tokens from your server, never from a browser or a phone app.
- Use the Stage service account while you build and test.

**WATCH FOR**
- Send the token request as a URL-encoded form, not JSON.
- Never log or share the token or the service account password.
- Tokens expire after one hour.

## Troubleshooting

**Q: The token call returns an invalid grant error.**
A: Check the username and password, and that you're using the service account for the environment you're calling.

**Q: Calls fail after working for a while.**
A: The token has probably expired. Tokens last an hour, so request a new one.

**Q: Where do I see the token call in full?**
A: In Documentation, open Auth, then Obtain access token. It shows the request, the responses, code examples and a Test Request button.

## Need Help?

Email RAZE support at contact@getaraze.com, or send a support request from https://getaraze.com/tools.
