WeatherAPI.com provides access to weather and geo data via a JSON/XML restful API. It allows developers to create desktop, web and mobile applications using this data very easy.
We provide following data through our API:
-
Real-time weather
-
10 day weather forecast
-
Astronomy
-
Time zone
-
Location data
-
Search or Autocomplete API
-
NEW: Historical weather
You need to signup and then you can find your API key under your account, and start using API right away!
If you find any features missing or have any suggestions, please contact us.
API access to the data is protected by an API key. If at anytime, you find the API key has become vulnerable, please regenerate the key using Regenerate button next to the API key.
Authentication to the WeatherAPI.com API is provided by passing your API key as request parameter through an API .
key=YOUR_API_KEY
The generated code uses the Newtonsoft Json.NET NuGet Package. If the automatic NuGet package restore is enabled, these dependencies will be installed automatically. Therefore, you will need internet access for build.
"This library requires Visual Studio 2017 for compilation."
- Open the solution (WeatherAPI.sln) file.
- Invoke the build process using
Ctrl+Shift+B
shortcut key or using theBuild
menu as shown below.
The build process generates a portable class library, which can be used like a normal class library. The generated library is compatible with Windows Forms, Windows RT, Windows Phone 8, Silverlight 5, Xamarin iOS, Xamarin Android and Mono. More information on how to use can be found at the MSDN Portable Class Libraries documentation.
The following section explains how to use the WeatherAPI library in a new console project.
For starting a new project, right click on the current solution from the solution explorer and choose Add -> New Project
.
Next, choose "Console Application", provide a TestConsoleProject
as the project name and click OK
.
The new console project is the entry point for the eventual execution. This requires us to set the TestConsoleProject
as the start-up project. To do this, right-click on the TestConsoleProject
and choose Set as StartUp Project
form the context menu.
In order to use the WeatherAPI library in the new project, first we must add a projet reference to the TestConsoleProject
. First, right click on the References
node in the solution explorer and click Add Reference...
.
Next, a window will be displayed where we must set the checkbox
on WeatherAPI.Standard
and click OK
. By doing this, we have added a reference of the WeatherAPI.Standard
project into the new TestConsoleProject
.
Once the TestConsoleProject
is created, a file named Program.cs
will be visible in the solution explorer with an empty Main
method. This is the entry point for the execution of the entire solution.
Here, you can add code to initialize the client library and acquire the instance of a Controller class. Sample code to initialize the client library and using controller methods is given in the subsequent sections.
The generated SDK also contain one or more Tests, which are contained in the Tests project. In order to invoke these test cases, you will need NUnit 3.0 Test Adapter Extension for Visual Studio. Once the SDK is complied, the test cases should appear in the Test Explorer window. Here, you can click Run All to execute these test cases.
In order to setup authentication and initialization of the API client, you need the following information.
Parameter | Description |
---|---|
key | TODO: add a description |
API client can be initialized as following.
// Configuration parameters and credentials
string key = "key";
WeatherAPIClient client = new WeatherAPIClient(key);
The singleton instance of the APIsController
class can be accessed from the API Client.
APIsController aPIs = client.APIs;
Current weather or realtime weather API method allows a user to get up to date current weather information in json and xml. The data is returned as a Current Object.Current object contains current or realtime weather information for a given city.
Task<Models.CurrentJsonResponse> GetRealtimeWeather(string q, string lang = null)
Parameter | Tags | Description |
---|---|---|
q | Required |
Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
lang | Optional |
Returns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'. |
string q = "q";
string lang = "lang";
Models.CurrentJsonResponse result = await aPIs.GetRealtimeWeather(q, lang);
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
Forecast weather API method returns upto next 10 day weather forecast and weather alert as json. The data is returned as a Forecast Object.
Forecast object contains astronomy data, day weather forecast and hourly interval weather information for a given city.
Task<Models.ForecastJsonResponse> GetForecastWeather(
string q,
int days,
DateTime? dt = null,
int? unixdt = null,
int? hour = null,
string lang = null)
Parameter | Tags | Description |
---|---|---|
q | Required |
Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
days | Required |
Number of days of weather forecast. Value ranges from 1 to 10 |
dt | Optional |
Date should be between today and next 10 day in yyyy-MM-dd format |
unixdt | Optional |
Please either pass 'dt' or 'unixdt' and not both in same request. unixdt should be between today and next 10 day in Unix format |
hour | Optional |
Must be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6 |
lang | Optional |
Returns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'. |
string q = "q";
int days = 160;
DateTime? dt = DateTime.Now();
int? unixdt = 160;
int? hour = 160;
string lang = "lang";
Models.ForecastJsonResponse result = await aPIs.GetForecastWeather(q, days, dt, unixdt, hour, lang);
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
History weather API method returns historical weather for a date on or after 1st Jan, 2015 as json. The data is returned as a Forecast Object.
Task<Models.HistoryJsonResponse> GetHistoryWeather(
string q,
DateTime dt,
int? unixdt = null,
DateTime? endDt = null,
int? unixendDt = null,
int? hour = null,
string lang = null)
Parameter | Tags | Description |
---|---|---|
q | Required |
Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
dt | Required |
Date on or after 1st Jan, 2015 in yyyy-MM-dd format |
unixdt | Optional |
Please either pass 'dt' or 'unixdt' and not both in same request. unixdt should be on or after 1st Jan, 2015 in Unix format |
endDt | Optional |
Date on or after 1st Jan, 2015 in yyyy-MM-dd format'end_dt' should be greater than 'dt' parameter and difference should not be more than 30 days between the two dates. |
unixendDt | Optional |
Date on or after 1st Jan, 2015 in Unix Timestamp format unixend_dt has same restriction as 'end_dt' parameter. Please either pass 'end_dt' or 'unixend_dt' and not both in same request. e.g.: unixend_dt=1490227200 |
hour | Optional |
Must be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6 |
lang | Optional |
Returns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'. |
string q = "q";
DateTime dt = DateTime.Now();
int? unixdt = 160;
DateTime? endDt = DateTime.Now();
int? unixendDt = 160;
int? hour = 160;
string lang = "lang";
Models.HistoryJsonResponse result = await aPIs.GetHistoryWeather(q, dt, unixdt, endDt, unixendDt, hour, lang);
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
WeatherAPI.com Search or Autocomplete API returns matching cities and towns as an array of Location object.
Task<List<Models.SearchJsonResponse>> SearchAutocompleteWeather(string q)
Parameter | Tags | Description |
---|---|---|
q | Required |
Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
string q = "q";
List<Models.SearchJsonResponse> result = await aPIs.SearchAutocompleteWeather(q);
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
IP Lookup API method allows a user to get up to date information for an IP address.
Task<Models.IpJsonResponse> GetIpLookup(string q)
Parameter | Tags | Description |
---|---|---|
q | Required |
Pass IP address. |
string q = "q";
Models.IpJsonResponse result = await aPIs.GetIpLookup(q);
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
Return Location Object
Task<Models.TimezoneJsonResponse> GetTimeZone(string q)
Parameter | Tags | Description |
---|---|---|
q | Required |
Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
string q = "q";
Models.TimezoneJsonResponse result = await aPIs.GetTimeZone(q);
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
Return Location and Astronomy Object
Task<Models.AstronomyJsonResponse> GetAstronomy(string q, DateTime dt)
Parameter | Tags | Description |
---|---|---|
q | Required |
Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
dt | Required |
Date on or after 1st Jan, 2015 in yyyy-MM-dd format |
string q = "q";
DateTime dt = DateTime.Now();
Models.AstronomyJsonResponse result = await aPIs.GetAstronomy(q, dt);
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |