I am using the code below to fetch NIFTY option data. While the Expiry date and format are also correct I am getting error.
Code:
function 2: Fetch NIFTY options chain data (update `instrument_key` before running)
function fetchUpstoxNiftyOptions() {
var expiryDate = "2025-03-13"; // Update with the correct expiry date
var instrumentKey = "NSE_OPT|NIFTY|2025-03-13";
var url = "https://api.upstox.com/v2/option/chain?instrument_key=" + encodeURIComponent(instrumentKey) + "&expiry_date=" + expiryDate;
var options = {
"method": "GET",
"headers": {
"Authorization": "Bearer 1ABCDXYZ",
"Accept": "application/json"
},
"muteHttpExceptions": true
};
Error:
12:48:35 AM Notice Execution started
12:48:36 AM Info {"status":"error","errors":[{"errorCode":"UDAPI100011","message":"Invalid Instrument key","propertyPath":null,"invalidValue":null,"error_code":"UDAPI100011","property_path":null,"invalid_value":null}]}
12:48:36 AM Info Error: 'data' field is empty. Try using a different expiry date or instrument_key.
12:48:37 AM Notice Execution completed