How to get access token using api key and secret

Rest assured that the provided code below has been tested and matches the code found in the Example Codes - Login section.

let UpstoxClient = require('upstox-js-sdk');

let apiInstance = new UpstoxClient.LoginApi();
let apiVersion = "2.0"; 
let opts = { 
  'code': "{your_auth_code}", 
  'clientId': "{your_client_secret}", 
  'clientSecret': "{your_client_secret}", 
  'redirectUri': "{your_redirect_url}", 
  'grantType': "authorization_code" 
};
apiInstance.token(apiVersion, opts, (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ' + JSON.stringify(data));
  }
});

Please verify that you are using the correct values in the opts object:

  • Refer to the API Documentation for code generation.
  • Note that clientId and clientSecret refer to your API Key and API Secret respectively, which are associated with your app. You can find them under My Account -> App -> My Apps -> Your App Name.
  • Ensure that redirectUri matches the redirect URI you specified during app creation.

For detailed instructions on creating an Upstox API app, see How to create an API app. Additionally, explore the API Documentation for a deeper understanding of the Upstox API.