Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Response Text: {"success":false,"message":"Invalid Token","errorCode":"AG8001","data":""}

    Test
    0
    2
    18
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hari-12345678 last edited by

      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);
      }
      }

      M 1 Reply Last reply Reply Quote 0
      • M
        Moderator_3 @hari-12345678 last edited by Moderator_3

        Hi @hari-12345678 Kindly make sure "Invalid Token" occurs while request initiated with expired/unauthorized token on any smartAPI. We expect the client to login everyday to consume the provided APIs. Kindly pass the recently fetched token via API and Please share us the API request, and header passed to analyze further if the issue still occurs.

        Regards,
        SmartAPI Team.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post