Dark Sky Forecast

Posted by agiletortoise, Last update almost 6 years ago

Example action demonstrates communication with the API. To use this example you will need a Dark Sky API key, which can be acquired by signing up for a free account at the Dark Sky API site.

The first time this action is run, you will be prompt to add a Dark Sky API key, which will be remembered in Credentials for future use.

This example calls the Dark Sky Forecast API for the current location, and displays a prompt with some key information from the forecast data. Additional data is available, this is only meant as an example of the possibilities - see API documentation for additional details.

The action also offers a link to open the full forecast at the Dark Sky website.


  • script

    // set personal API key credential
    let credential = Credential.create("Dark Sky API Key", "Enter your Dark Sky API key, which can be copied from the developer console page after creating a free account.");
    credential.addTextField("key", "API Key");
    let apiKey = credential.getValue("key");
    // method to fetch forecast data
    let getForecast = (latitude, longitude) => {
    	// build URL to Dark Sky API forecast endpoint
    	let endpoint = `${apiKey}/${latitude},${longitude}`;
    	// create and make HTTP request
    	let http = HTTP.create();
    	let response = http.request({
    		"url": endpoint,
    		"method": "GET"
    	// check for a success 200 response
    	if (response.statusCode != 200) {;
    		console.log("Dark Sky Error: " + response.error);
    		return null;
    	// parse response JSON to object
    	let data = JSON.parse(response.responseText);
    	if (!data) {;
    		console.log("Dark Sky Error: Unable to parse response");
    		return null;
    	// return the forecast data object
    	return data;	
    let lat = draft.processTemplate("[[latitude]]")
    let lon = draft.processTemplate("[[longitude]]");
    let darkSkyURL = `${lat},${lon}`;
    let data = getForecast(lat, lon);
    if (data) {
    	// See details on all information in response at API docs
    	let d = [];
    	d.push(`Temperature: ${data.currently.temperature}`);
    	d.push(`Summary: ${data.currently.summary}`);
    	d.push(`Expected: ${data.minutely.summary}`);
    	d.push(`Today's High: ${[0].temperatureHigh}`);
    	d.push(`Today's Low: ${[0].temperatureLow}`);
    	let p = Prompt.create();
    	p.title = "Dark Sky Forecast";
    	p.message = d.join("\n");
    	p.addButton("Open at");
    	if ( {
    		app.openURL(darkSkyURL, true);
    else {
    	alert("Unable to fetch Dark Sky forecast information. Check action log for details");


  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.