Hi 🙂 I am tying to call back tide station data to populate a survey form using Admiralty API. I used to use csv files for the approprate stations / day / tide data but I have to update these every year manually. Yawn!
I have not come accross request headers using JavaScript before and I am struggling with the syntax. what I have so far is...
function runTideCalcs(){
Â
var xmlhttp = new XMLHttpRequest();
Â
var url = `https://admiraltyapi.azure-api.net/uktidalapi/api/V1/Stations/0065/TidalEvents?duration=1`;
Â
xmlhttp.open("GET",url,false);
xmlhttp.send();
Â
if (xmlhttp.status!=200){
return null;
} else {
var responseJSON=JSON.parse(xmlhttp.responseText)
if (responseJSON.error){
return responseJSON.error;
} else {
if (responseJSON){
return JSON.stringify(responseJSON);
}
else {
return "";
}
}
}
}
....But I am not sure what syntax or where to incorporate the
Â
setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}");
Â
Naturally I have an Admiralty account and Sub. key. Any pointers would be very welcome.
Â
Thanks
Chris
Â