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

https://<base_url>/iam/oauth/v2/token?grant_type=authorization_code&client_id=<client_id>&client_secret=<client_secret>&redirect_uri=<redirect_uri>&code=<authorization_code>

Request Method

POST

where,

base_urlThe 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_secretThe client credentials that were generated when you registered the client application
redirect_uriOne of the authorized redirect URIs that you associated while registering the client application
codeThe 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

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.