message: 'Invalid `checksum`.',

Akashakhan
I have bought kite API key and secret Key today and I am getting this invalid checksum error eventhough i am entering correct apiKey,requestToken and apiSecret.
below is my code to generate CheckSum and request refresh token
function generateChecksum( apiKey, requestToken, apiSecret ) {
return crypto
.createHmac( 'sha256', apiSecret )
.update( apiKey + requestToken + apiSecret )
.digest( 'hex' );
}
app.get( '/redirect', async ( req, res ) => {
const requestToken = req.query.request_token;

if ( !requestToken ) {
return res.status( 400 ).send( 'Request token not found' );
}

console.log( 'Request Token:', requestToken );

const checksum = generateChecksum( apiKey, requestToken, apiSecret );
console.log( 'Generated Checksum:', checksum );

const formData = new URLSearchParams();
formData.append( 'api_key', apiKey );
formData.append( 'request_token', requestToken );
formData.append( 'checksum', checksum );

try {
const response = await axios.post( 'https://api.kite.trade/session/token', formData, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
} );

const accessToken = response.data.data.access_token;
const refreshToken = response.data.data.refresh_token;

console.log( 'Access Token:', accessToken );
console.log( 'Refresh Token:', refreshToken );
res.send( `Access token and refresh token generated successfully.` );
} catch ( error ) {
console.error( 'Error generating access token:', error.response ? error.response.data : error.message );
res.status( 500 ).send( 'Failed to generate access token' );
}
} );
Sign In or Register to comment.