Just a quick note to say thank you. The code above was very helpful.
Original Message:
Sent: 06-26-2025 09:21
From: Richard Hills
Subject: Handling ogscript.asyncHTTP response code 401
Antony,
Thank you for the reply. I will have a closer look at the code snipit you sent.
I think what has confused me is that when the request fails with 401 error this is not passed to the callback, but 200 success is, all I get is null.
I will keep digging. Thank you
------------------------------
Richard Hills
------------------------------
Original Message:
Sent: 06-26-2025 08:47
From: Antony Giraldo
Subject: Handling ogscript.asyncHTTP response code 401
Hi Richard,
So because you are getting a 401 response that indicates your request lacks valid authentication credentials, you might need to provide more information to authenticate via the header. When you wish to provide headers using this method instead of providing "application/json" in the 3rd argument, if you provide a json object you can fully build out your header that way.
Here is an example for pulling weather data in Ottawa, ON Canada that uses headers:
var url = "https://api.open-meteo.com/v1/forecast?latitude=45.4215&longitude=-75.6998&hourly=temperature_2m";var method = "GET";var data = null;var headers = {};headers["User-Agent"] = "Mozilla/5.0";headers["Accept"] = "application/json";headers["Connection"] = "close";ogscript.asyncHTTP(url, method, headers, data, function(response) { if (response != null && response != undefined) { try { var json = JSON.parse(response); var lat = json.latitude; var lon = json.longitude; var times = json.hourly.time; var temps = json.hourly.temperature_2m; ogscript.debug("Weather Forecast for Coordinates: " + lat + ", " + lon); ogscript.debug("Showing first 5 hourly temperatures:"); for (var i = 0; i < 5; i++) { var timeStr = times[i]; var tempStr = temps[i]; ogscript.debug(timeStr + " → " + tempStr + "°C"); } ogscript.debug("Forecast retrieved successfully."); } catch (e) { ogscript.debug("Failed to parse JSON: " + e); } } else { ogscript.debug("No response received."); }});
------------------------------
Antony Giraldo
DashBoard Custom Panel Developer
Ross Video Creative Services | Rocket Surgery Triggering and Control
Original Message:
Sent: 06-26-2025 02:18
From: Richard Hills
Subject: Handling ogscript.asyncHTTP response code 401
I also implemented a try-catch, but this did not work either.
try {
ogscript.asyncHTTP(url, method, "application/json", data, httpCallback, true);
}
catch(err) {
ogscript.debug('***' + err.message);
}
------------------------------
Richard Hills