Issue with API Token Usage Across Different Endpoints

With the help of headers, I am able to call historical candles, and it returns data. However, when I query for margins or try to place an order using the same set of headers, it says “Invalid token used to access API.” Can someone help me?

import requests
access_token= "fav access token"


headers = {
    'Accept': 'application/json',
    'Authorization': f"Bearer {access_token}",
    
}
url = "https://api.upstox.com/v2/historical-candle/intraday/NSE_EQ|INE002A01018/1minute"
response = requests.request("GET", url, headers=headers, data={})
print(response.text[:100])


url = "https://api.upstox.com/v2/user/get-funds-and-margin"
response = requests.request("GET", url, headers=headers, data ={})
print(response.text)

{'status': 'success', 'data': {'candles': [['2024-09-24T14:49:00+05:30', 2988, 2988.05, 2986.7, 2986
{"status":"error","errors":[{"errorCode":"UDAPI100050","message":"Invalid token used to access API","propertyPath":null,"invalidValue":null,"error_code":"UDAPI100050","property_path":null,"invalid_value":null}]}

@Pradeep_Jaiswar any help is much appreciated pal.

FYI

api_key *****
account_id *****

thanks in advance

My bad, forget it. I messed up the access token. It’s working fine now. Thanks for your time!

2 Likes

Hi @Srinadha_Reddy, Thanks for updating