Issue with Fetching OHLC Data - Need Community Insights

I've been working on a Google Apps Script to fetch OHLC data for multiple stock symbols from the Kite Connect API. I've ensured that my API key and access token are correct, and I've followed the API documentation. However, I keep encountering an "Incorrect api_key or access_token" error.

Steps Taken:

Verified API credentials: I've double-checked that my API key and access token are accurate.
Rate limiting: I've ensured that I'm not exceeding any rate limits imposed by the API.
I'm at a loss for the cause. I'm reaching out to the community to see if anyone has encountered a similar issue or can provide guidance on what might be going wrong.

If you've had experience with fetching OHLC data from the Kite Connect API or if you have any insights into why I might be encountering this error, I would greatly appreciate your help.

I've included the test code snippet I'm using below for reference

function fetchOHLCData() {
var apiKey = 'hidden';
var accessToken = 'hidden';

var stockSymbols = ['NSE:INFY', 'BSE:SENSEX', 'NSE:NIFTY+50'];

var baseUrl = '';
var url = baseUrl + stockSymbols.join('&i=');

try {
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'token ' + apiKey + ':' + accessToken,
'X-Kite-Version': '3'
muteHttpExceptions: true

// Parse the JSON response
var data = JSON.parse(response.getContentText());

if (data) {

SpreadsheetApp.getUi().alert('OHLC data has been fetched.');
} else {
Logger.log('Data not found.');
} catch (error) {
Logger.log('Error fetching OHLC data: ' + error);
  • rakeshr
    I keep encountering an "Incorrect api_key or access_token" error
    Is all auth throwing this error? Or it's coming intermittently.
Sign In or Register to comment.