Generate Access Token and Refresh Token
Once the client application receives an authorization code, it can exchange it for an access token by making the following request:
Request URL
Request Method
POST
where,
base_url | The base URL of your ManageEngine Account For example, the base URL is either https://host_name:port_number (learn more) or appcreatordemo.manageengine.com (hostname of the server where ManageEngine AppCreator is running). |
client_id & client_secret | The client credentials that were generated when you registered the client application |
redirect_uri | One of the authorized redirect URIs that you associated while registering the client application |
code | The authorization code that was generated upon making the authorization request |
Understanding the response
The success or failure of the API will be conveyed in its response. The response of the generate token API will include:
- access_token
The access token that the requesting user will need to access the resources that correspond to the scopes that were included while making the authorization request.
- refresh_token
The refresh token that will be required to refresh the requesting user's access token.
- expires_in
The time (in seconds) after which the access token will expire.
- api_domain
The domain where the API calls are to be made for the requesting user. Though the value will contain the zohoapis domain, the client application must use the machine name and port number in its API requests. The client must make the API requests at https://host_name:port_number/iam
- token_type
This indicates the generated token's type. The value Bearer indicates that it's an access token.
Note
- An access token is valid for only an hour and can be used only to perform the operations defined by the scopes that were included while making the authorization request.
- A refresh token has no expiry. However, it can be revoked. Its purpose is to refresh the access token upon its expiry.
- A maximum of five refresh tokens can be generated per minute.
Possible Errors
- invalid_client
- Ensure that you have passed the right client ID and client secret
- Ensure that you have used the same Zoho account base URL that you used while making the authorization request
- invalid_code
- The authorization code that you generated may either have expired or already been exchanged for an access token
- The refresh token that was used to generate the access token may either have expired or been revoked
- invalid_redirect_uri
The redirect URI given in the request is not one that was associated while registering the client application
Sample Request
Copiedcurl "https://appcreatordemo.manageengine.com/iam/oauth/v2/token?grant_type=authorization_code&code=1000.xxxxxxd34d.xxxxxxx909a&client_id=1000.xxxxxxxxxxHF2C6H&redirect_uri=https://www.zylker.com/callback&client_secret=xxxxxxxxx4f4f7a"
-X POST
Sample Response
Copied{
"access_token": "1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf",
"refresh_token": "1000.3ph66exxxxxxxxxxxxx6ce34.3c4xxxxxxxxxxxxxxxf",
"api_domain": "https://www.zohoapis.com",
"token_type": "Bearer",
"expires_in": 3600
}
Though the api_domain key in the response contains the zohoapis domain, the client application must use the machine name and port number in its API requests. The client must make the API requests at either appcreatordemo.manageengine.com (hostname of the server where ManageEngine AppCreator is running) or https://host_name:port_number/iam.