How do I retrieve weather data using an ODATA request?

Overview

This article describes how to retrieve weather data such as weather forecast, historical weather observations and historical climate summaries using an ODATA based request.

What is ODATA and when should I use it?

According to odata.org:

OData (Open Data Protocol) is an ISO/IEC approvedOASIS standard that defines a set of best practices for building and consuming RESTful APIs. OData helps you focus on your business logic while building RESTful APIs without having to worry about the various approaches to define request and response headers, status codes, HTTP methods, URL conventions, media types, payload formats, query options, etc. 

ODATA is therefore a convenient way to retrieve structured data like grids or tables of information such as weather data sets. The tools you use may provides a simple way to import data from ODATA requests such as SAP Analytics Cloud. Supplying the weather data in this format therefore makes it quick and easy to import the weather data into the tool.

How to construct the weather data request

We are going to create a Visual Crossing Weather API query. From this query, we can request a pre-built request in ODATA format.

The easiest way to construct the weather data request is to use the Weather Data Services page to construct the query. From here you can set the locations to pull data for, choose type of weather data you are interested in, modify the parameters and view the data in the browser. You can also download the data directly into the browser.

For more information on signing up and creating your first Weather Data Services query in the weather API, please How do I get started with the Weather API?

When you have created a weather API link, you should see the following:

mceclip2.png

This is a sample of a Weather API query that will retrieve the weather forecast for a single location. 

Creating the ODATA link

By default the weather API queries are formatted as a GET based request. However you can also specify to format the request as a POST or ODATA request.

To create an ODATA request for the Weather Data, click switch to the ODATA format:

mceclip1.png

The resulting ODATA query completely encapsulates the requested weather data in a single ODATA request:

mceclip3.png

If you copy this query, you can use it directly in your tool. If you place the query into a browser address bar you will see the following output:

mceclip4.png

To retrieve the actual data, append /WxRequest to the of of the URL. Note that some tools will require the URL with the /WxRequest added and some, such as a SAP Analytics Cloud will prompt you.  When prompted you should choose the WxRequest option.

The final data when viewed in the browser, will resemble:

mceclip6.png

 

To learn more about constructing the weather data request, please see Getting Started With Weather Data Services. To learn more about the Weather API, please see Weather API page.

 

 

 

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.