Hello,
I created a simple script action which pulls the current temperature from the OpenWeatherMap API. This works fairly well. But I would like to use the action as template tag in one of my templates that I create with the excellent New Draft with Template
Action. But it seems that the template tag is not handed through in the New Draft with Template
Action even if I include the Temperature Action before the New Draft with Template
.
Here is my action so far:
let credential = Credential.create("Open Weather Map API Key", "Enter your Open Weather Map API key, which can be copied from the Open Weather Map developer console page after creating a free account.");
credential.addTextField("key", "API Key");
credential.authorize();
let apiKey = credential.getValue("key");
let getTemperature = (latitude, longtitide, units = 'metric') => {
let endpoint = `http://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longtitide}&units=${units}&appid=${apiKey}`;
let http = HTTP.create();
let response = http.request({
"url": endpoint,
"method": "GET"
});
if (response.statusCode != 200) {
context.fail();
console.log("Openweathermap Error: " + response.error);
return null;
}
// parse response JSON to object
let data = JSON.parse(response.responseText);
if (!data) {
context.fail();
console.log("OpenweathermapError: Unable to parse response");
return null;
}
// return the forecast data object
return data;
}
let lat = draft.createdLatitude;
let lon = draft.createdLongitude;
let units = 'metric';
let data = getTemperature(lat, lon, units);
if (data) {
let temperature = data.main.temp + '°C';
alert(temperature);
draft.setTemplateTag("temperature", temperature);
}
The temperature will be returned in the alert but the [[temperature]] is not rendered in the new draft. What am I missing @agiletortoise?