One of the most common API requirements is to obtain multiple pieces of information for a location. This can be completed with multiple API requests for each data type, but the batch request feature provides a more efficient solution. With a batch request, you can query multiple endpoints within a single query without having to learn a new endpoint or request format.
The batch endpoint uses a requests parameter whose value is a string of comma-separated standard endpoint requests. Each endpoint request must include either an :action or :id along with optional parameters for each request. Each individual request string should be exactly the same as if you were making the request individually, following the same format outlined in each endpoint's documentation.
Additionally, the batch request also supports all of the standard endpoint parameters, such as p, limit, and query, except that when used, these batch parameters are considered global and applied to each individual request provided with the request's parameters. Note, however, that any parameters included within an individual request (within the requests parameter) will override those same global options found in the main batch request. For example:
In this batch request, the global option
limit=10 is used by the observations and the fires endpoints, but the stormreports endpoint overrides this with it’s own
Heads Up! Each individual request you include within a single batch call counts as a separate API access against your account's daily limit. So the above example requesting /observations, /stormreports and /fires would be counted as three API accesses, not one. The /batch endpoint is simply available for convenience.
Fetch multiple data types for the same location
The is the simplest and most common use of a batch request:
For example, to fetch the latest observation, daily forecast and active advisories for Minneapolis, MN:
Parameters can be passed to each individual endpoint as well but must be URL-encoded, use "%3F" for "?" and "%26" for "&". For example, to obtain the latest observation, the forecast in daily intervals, the forecast in hourly intervals and all active advisories, the batch request would be:
Fetch data for multiple locations
To fetch the latest observations for Atlanta, Minneapolis, and Seattle:
Fetch weather extremes
The following batch request is combined with the power of the query and sort parameters to return the warmest and coldest locations in the US based on their latest observations:
Here the “query=country:us,temp:-999” queries only observations in the US and only includes observations that have a valid temperature (observations that didn’t report a temperature for a particular hour will have -999 as the temperature value, so we would want to eliminate those that didn’t report).
Often during the winter months, the warmest location in the US may be in Puerto Rico. So, adjust the query to eliminate locations in Puerto Rico to query only the 50 states:
While the batch request capability is powerful, there is currently a maximum limit of twenty-five (25) endpoint requests per API query. This is normally more than sufficient for most needs, though we will continue to re-evaluate this limit in the future.
Last modified: January 13, 2020