We recently built a demo that highlights how Flow can be used to personalize emails, and we picked weather as a good example of the kind of real-time data that you have to make a call out for. As part of that demo, we built the action that’s packaged here. The service we use is called Visual Crossing:
…and they have a nice free tier. Sign up and you get issued a token that you can paste into this action.
Here’s a video:
How it Works
In the first version of this action, you can configure these inputs:
|Key||Provided by Visual Crossing with your account|
|locations||One or more address, partial address or latitude, longitude values for the required locations . Addresses can be specified as full addresses. The system will also attempt to match partial addresses such as city, state, zip code, postal code and other common formats.|
When specify a point based on longitude, latitude, the format must be specified as latitude,longitude where both latitude and longitude are in decimal degrees. latitude should run from -90 to 90 and longitude from -180 to 180 (with 0 being at the prime meridian through London, UK).
Data for multiple locations can be requested in a single request by concatenating multiple locations using the pipe (|) character.
|Format||either csv or json. csv is good for downloading data. json is what you should stick with if you want to use individual values later in your flow|
|Interval||The interval between weather forecast data in the output. 1 represents an hourly forecast, 24 represents a daily forecast. As the source data is calculated at the hourly level, records calculated at 12 or 24 hours are aggregated to indicate the predominant weather condition during that time period. For example the maximum temperature, total precipitation, maximum windspeed etc.|
Supported values 1, 12 or 24.
|Unit Group||Set to ‘us’, ‘metric’,’uk’, or ‘base’. Default is ‘us’. More info.|
Working With the Return Values
This is the kind of action where calling it is simple, but dealing with the deluge of data you get back can be challenging. We’ve configured the action to provide some tools, however.
The easiest way to consume the weather data is to reference the SingleLocationReport object that gets returned. Note that if you pass in more than one Location, singleLocationReport will simply use the first Location you provide.
There are some useful pieces of information in singleLocationReport (this is also a great way to get longitudes and latitudes and time zones), but the most valuable stuff is one level deeper, in currentConditions:
‘wspd’ is wind speed and ‘wdir’ is wind direction. For more information on these weather concepts, see this.
As an example, here’s how I’d make a decision based on the amount of rainfall
More complete output is available via the responseBody (which is the unmodified response JSON) and the FullLocationsReport, which is a List of the WeatherLocation object that is returned as the singleLocationReport.
Developer Notes: How It’s Done
To get the weather to show up in an easily referenceable format, we took advantage of a powerful Flow capability called Apex-Defined Types, also known as Custom Types. If you look inside the package that this action is part of, you’ll see several data structures. Here’s one of them, which we called WeatherLocation:
The @auraEnabled annotations tell Flow that this is an object that has fields that should be exposed in Flow Builder.
Here are some good introductions to Apex Types