Request failed with status code: 404

I am trying to access historical data as per API documentation and I am getting error code 404, please help

Here is the Code
*******>

import requests

Replace ‘YOUR_ACCESS_TOKEN’ with your actual access token

access_token = access_token

Set common headers

headers = {
‘accept’: ‘application/json’,
‘Api-Version’: ‘2.0’,
‘Authorization’: f’Bearer {access_token}’
}

Define the API endpoint URL

symbol = ‘NSE_FO|35048’
timeframe = ‘1minute’
start_date = ‘2023-09-14’ # The date of the last trading session
end_date = ‘2023-09-14’ # Same as start date
url = f’https://api-v2.upstox.com/historical-candle/{symbol}/{timeframe}

Send a GET request to retrieve historical candle data

params = {
‘start_date’: start_date,
‘end_date’: end_date,
}

try:
response = requests.get(url, headers=headers, params=params)

# Check if the request was successful (status code 200)
if response.status_code == 200:
    historical_data = response.json()
    print(historical_data)
    # Process the historical candle data as needed
    # Your code to calculate the Nadaraya Watson envelope and upper/lower values can go here

else:
    print(f"Request failed with status code: {response.status_code}")
    print(response.text)

except Exception as e:
print(f"An error occurred: {str(e)}")
######################################
Output:

Request failed with status code: 404
{“status”:“error”,“errors”:[{“errorCode”:“UDAPI100060”,“message”:“Resource not Found.”,“propertyPath”:null,“invalidValue”:null,“error_code”:“UDAPI100060”,“property_path”:null,“invalid_value”:null}]}

Please Help

@rakesh_ahuja

To build the historical API’s URL, use the following path variables:

  • instrumentKey
  • interval
  • to_date
  • from_date

Once assembled, the URL should resemble:

https://api-v2.upstox.com/historical-candle/NSE_FO%7C35048/1minute/2023-09-14/2023-09-14

Please ensure the URL is constructed correctly.

Thank you!