Tokens Endpoint
Endpoint: GET /oauth/token
The token endpoint is used to exchange the authorization code for an access token or to refresh an expired access token.
Authorization Code Flow
Request Parameters:
client_id: The client ID of your application (obtained during app registration)client_secret: The client secret of your application (obtained during app registration)grant_type: Use authorization_code for the authorization code flowcode: The authorization code received from the authorization endpointredirect_uri: The same redirect URI used during the authorization process
Example Request:
- curl
 - Node.js
 
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&code=AUTHORIZATION_CODE&redirect_uri=YOUR_REDIRECT_URI" "https://api.commoninja.com/oauth/token"
const axios = require('axios');
async function getData() {
    const data = {
        client_id: 'YOUR_CLIENT_ID',
        client_secret: 'YOUR_CLIENT_SECRET',
        grant_type: 'authorization_code',
        code: 'AUTHORIZATION_CODE',
        redirect_uri: 'YOUR_REDIRECT_URI'
    };
    const config = {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    };
    const response = await axios.post('https://api.commoninja.com/oauth/token', new URLSearchParams(data), config);
    
    return response.data;
}
getData();
Example Response:
{
  "access_token": "ACCESS_TOKEN",
  "expires_in": "EXPIRATION_DATE",
  "refresh_token": "REFRESH_TOKEN",
  "refresh_token_expires_in": "EXPIRATION_DATE"
}
Refresh Token Flow
Request Parameters:
client_id: The client ID of your application (obtained during app registration)client_secret: The client secret of your application (obtained during app registration)grant_type: Userefresh_tokenfor the refresh token flowrefresh_token: The refresh token obtained during the initial token exchange
Example Request:
- curl
 - Node.js
 
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=refresh_token&refresh_token=REFRESH_TOKEN" "https://api.commoninja.com/oauth/token"
const axios = require('axios');
const querystring = require('querystring');
async function getData() {
    const postData = querystring.stringify({
        client_id: 'YOUR_CLIENT_ID',
        client_secret: 'YOUR_CLIENT_SECRET',
        grant_type: 'refresh_token',
        refresh_token: 'REFRESH_TOKEN'
    });
    const response = await axios.post('https://api.commoninja.com/oauth/token', postData, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
    
    return response.data;
}
getData();
Example Response:
{
  "access_token": "NEW_ACCESS_TOKEN",
  "expires_in": "NEW_EXPIRATION_DATE"
}