What is the issue with this request.. Im getting Invalid Token error
-
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': ''}
-
@Moderator_2 The document is outdated. when i passed the refresh_token and make it post API, it worked.
-
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 -
@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
-
@Phanilbb same issue with me and i am unable