Response Text: {"success":false,"message":"Invalid Token","errorCode":"AG8001","data":""}
-
running below code and seeing error
function fetchLtpBEL() {
var apiKey = 'Skeo2eR1';
var accessToken = '6591cba1-ed00-4e56-a88b-8d47fc21ff10';
var symbolToken = '500049'; // Replace with the actual symbol token for BEL
var exchange = 'NSE'; // National Stock Exchange// Angel One API endpoint for LTP
var endpoint = 'https://apiconnect.angelbroking.com/rest/secure/angelbroking/market/v1/quote';var payload = {
"symboltoken": symbolToken,
"exchange": exchange
};var headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + accessToken,
"x-api-key": apiKey
};var options = {
"method": "POST",
"headers": headers,
"payload": JSON.stringify(payload),
"muteHttpExceptions": true
};try {
var response = UrlFetchApp.fetch(endpoint, options);
var responseText = response.getContentText();Logger.log('Response Code: ' + response.getResponseCode()); Logger.log('Response Text: ' + responseText); var data = JSON.parse(responseText); if (data && data.data) { var ltp = data.data[0].ltp; // Assuming 'ltp' is the field for Last Traded Price Logger.log('BEL LTP: ' + ltp); return ltp; } else { Logger.log('Error: LTP data not found in response'); Logger.log('Full response: ' + JSON.stringify(data)); }
} catch (error) {
Logger.log('Error fetching LTP data: ' + error);
}
}