---
updatedAt: 2025-06-24T10:43:04.000Z
agentTools:
  projectIndex: https://developers.kommo.com/llms.txt
---

# Get/renew access token

```javascript JavaScript
const axios = require('axios');

const subdomain = '';
const clientId = '';
const clientSecret = '';
const authCode = '';
const redirectUri = '';

const baseUri = `https://${subdomain}.kommo.com/oauth2/access_token`;

const getToken = async (refreshToken) => {
  try {
    const headers = {
      accept: 'application/json',
      'content-type': 'application/json',
    };

    const body =
      refreshToken ? {
            client_id: clientId,
            client_secret: clientSecret,
            grant_type: 'refresh_token',
            refresh_token: refreshToken,
            redirect_uri: redirectUri,
          }
        : {
            client_id: clientId,
            client_secret: clientSecret,
            grant_type: 'authorization_code',
            code: authCode,
            redirect_uri: redirectUri,
        }

    const tokenResponse = await axios.post(baseUri, body, { headers });

    console.log('Token Response:', tokenResponse.data);
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
};

// in order to refresh token, pass the token value to the function
getToken('');
```

```json Response Example
{
  "token_type": "Bearer",
  "expires_in": 86400,
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.test-access-token-1234567890abcdefghij.XYZ123abcDEF456ghi789JKL",
  "refresh_token": "b97c0ff0-6c9d-4e3a-a02e-12345678abcd"
}
```

# Define your credentials

<!-- javascript@ -->

Specify the variables for authorization using OAuth 2.0: subdomain, client ID, secret, authorization code, and redirect URI.

Find out how to obtain the keys here: <https://developers.kommo.com/docs/oauth-20#/registration-of-an-integration>

# Get or update token

<!-- javascript@11-40 -->

Compose a body and send a POST request to obtain or update an access token using an authorization code or refresh token

# (Optional) Refresh token

<!-- javascript@43 -->

In order to refresh token, pass the token value to the function.