Generate an Access Token
After Motive associates your application to the master fleet, you must generate an access token for your company.
NOTE
You must implement an event listener that must capture the authorization code generated by Motive. This code is critical for generating the access token.
You must take the following two steps for generating your access token.
Step 1: Trigger the initial OAuth call
- Log in to your fleet on the Motive platform.
- Paste the following link. Ensure to add your own parameters for the variables.
- https://gomotive.com/oauth/authorize?client_id=<YOUR_CLIENT_ID>&redirect_uri=<YOUR_RE
DIRECT_URI>&response_type=<code>&scope=<freight_visibility.manage>
- https://gomotive.com/oauth/authorize?client_id=<YOUR_CLIENT_ID>&redirect_uri=<YOUR_RE
Variable | Description |
---|---|
client_id | Enter your client_id that is generated by Motive. |
redirect_uri | Enter the redirect URI that you enter when creating your company. |
response_type | Enter the code of the response type. |
scope | Set the scope as "freight_visibility.manage" |
The platform will redirect you to the corresponding URL, and prompt you to install the app.
- Click Install.
You will be redirected to the provided URI. The Motive platform will also generate an authorization code and append the same to the URL. - Make a note of the authorization code that is captured by your listener.
Step 2: Generate an access token
- Call the following endpoint:
-
Ensure to add the following variables:curl -X POST 'https://keeptruckin.com/oauth/token' -d 'grant_type=authorization_code&code=<AUTH_CODE>&redirect_uri=<REDIRECT_URI>&client_id= <CLIENT_ID>&client_secret=<CLIENT_SECRET>β
Variables | Description |
---|---|
grant_type | Mention the grant type as "authorization_code". |
code | Specify the authroization code that is generated by Motive and capture by your listener. |
redirect_uri | Specify the redirect_uri that you mention during the creation of your application. |
client_id | Specify your client_id |
client_secret | Specify your client_secret |
After you make the POST call, you will receive from the platform with the following info:
{
"access_token": "YOUR ACCESS TOKEN",
"token_type": "Bearer",
"expires_in": 7200,
"refresh_token": "YOUR REFRESH TOKEN"
}
Now you have successfully generated your access token.
NOTE
The access token is only valid for a period of 2 hours, prior to which the access token will expire. If you want to generate a new access token, you must repeat Step 2 and make a POST call again with the following modifications:
curl -X POST 'https://keeptruckin.com/oauth/token' -d
'grant_type=refresh_token&refresh_token=YOUR_REFRESH_TOKEN_HERE&redirect_uri=RE
DIRECT_URI&client_id=CLIENT_ID&client_secret=CLIENT_SECRETβ
Variables | Description |
---|---|
grant_type | Specify the grant type as refresh_token. |
refresh_token | Enter the refresh token to generate a new access token, |
redirect_uri | Specify the redirect_uri that you mention during the creation of your application. |
client_id | Specify your client ID. |
client_secret | Specify the client secret. |
NOTE
The TTL for the access token is time based, and the TTL for the refresh token is based on the usage. Access token expires after 2 hours of it's generation where as the refresh token expires as soon as it is used.
Updated 2 months ago