Navigation

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

    What is the issue with this request.. Im getting Invalid Token error

    General Discussion
    0
    5
    45
    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.
    • P
      Phanilbb last edited by

      def get_profile(angel_one_details, jwtToken):
          url = "https://apiconnect.angelbroking.com/rest/secure/angelbroking/user/v1/getProfile"
          headers = {
              'Content-Type': 'application/json',
              'Accept': 'application/json',
              'X-UserType': 'USER',
              'X-SourceID': 'WEB',
              'X-PrivateKey': angel_one_details['api_key'],
              'X-ClientLocalIP': "127.0.0.1",
              'X-ClientPublicIP': "106.193.147.98",
              'X-MACAddress': ':'.join(re.findall('..', '%012x' % uuid.getnode())),
              'Authorization': "Bearer {}".format(jwtToken)
          }
          r = requests.get(url, headers)
          print(r.json())
      

      Im getting the below response

      {'success': False, 'message': 'Invalid Token', 'errorCode': 'AG8001', 'data': ''}

      M N 2 Replies Last reply Reply Quote 0
      • N
        Naresh3599 @Phanilbb last edited by

        @Phanilbb same issue with me and i am unable

        1 Reply Last reply Reply Quote 0
        • A
          Ardent last edited by

          @Phanilbb said in What is the issue with this request.. I'm getting Invalid Token error:

          I have not changed but tried different

          import requests
          def get_profile(angel_one_details, jwt_token):
          RuntimeError: If the API request fails with a non-200 status code
          "https://apiconnect.angelbroking.com/rest/secure/angelbroking/user/v1"
          profile_endpoint = "getProfile"
          headers = {
          'Content-Type': 'application/json',
          'Accept': 'application/json',
          'X-UserType': 'USER',
          'X-SourceID': 'WEB',
          'X-PrivateKey': angel_one_details['api_key'],
          'Authorization': f"Bearer {jwt_token}" }
          url = f"{base_url}/{profile_endpoint}"
          response = requests.get(url, headers=headers)
          if response.status_code == 200:
          return response.json()
          else:
          raise RuntimeError(f"API request failed with status code: {response.status_code}")

          I hope it

          1 Reply Last reply Reply Quote 0
          • M
            Moderator_2 @Phanilbb last edited by

            hi @Phanilbb

            "Invalid Token" occurs if the passed token Expired/Invalid/Unauthorized. Kindly login and pass the fresh token to resolve the issue.

            Thanks & Regards,
            SmartAPI team

            P 1 Reply Last reply Reply Quote 0
            • P
              Phanilbb @Moderator_2 last edited by

              @Moderator_2 The document is outdated. when i passed the refresh_token and make it post API, it worked.

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