Weather by Location API

You can see pricing and an interactive version of this documentation on Mashape!

Documentation

This page is going to walk you through how to get your app or site set up with Mazon IO's Weather by Location API. This page will show some very basic integrations with .NET, Objective-C, Python, PHP, Ruby, and Node, but the API is language and framework agnostic: it returns JSON, so any programming environment with a JSON library can use the Weather by Location API. This page assumes you've created a Mashape account and have subscribed to our api and thereby have an API key to make requests.

So step 1 is to go and subscribe to our api:
Mashape

Below are some examples to get you started:


Making your first request
Making a request with the Weather by Location API is pretty simple. Here is a sample curl request via the Unix command line:
curl --get --include 'https://weatherinfo.p.mashape.com/api/weather/{ip_address}' \
  -H 'X-Mashape-Key: {your_mashape_key}' \
  -H 'Accept: application/json'
That should return a JSON object that depending on the fields you have selected looks something like this:
{
  "creationDate": "2016-05-02T04:09:37-05:00",
  "creationDateLocal": "2 May 03:53 am CDT",
  "credit": "http://www.weather.gov/mpx",
  "currentobservation": {
    "Altimeter": "1019.8",
    "Date": "2 May 03:53 am CDT",
    "Dewp": "35",
    "Gust": "0",
    "Relh": "83",
    "SLP": "30.11",
    "Temp": "40",
    "Visibility": "10.00",
    "Weather": "Fair",
    "Weatherimage": "nsct.png",
    "WindChill": "NA",
    "Windd": "0",
    "Winds": "0",
    "elev": "866",
    "id": "KMIC",
    "latitude": "45.06",
    "longitude": "-93.35",
    "name": "Minneapolis, Crystal Airport",
    "state": "MN",
    "timezone": "CDT"
  },
  "data": {
    "hazard": [],
    "hazardUrl": [],
    "iconLink": [
      "http://forecast.weather.gov/newimages/medium/few.png",
      "http://forecast.weather.gov/newimages/medium/nfew.png",
      "http://forecast.weather.gov/DualImage.php?i=few&j=hi_shwrs&jp=40",
      "http://forecast.weather.gov/DualImage.php?i=hi_nshwrs&j=nfew&ip=30",
      "http://forecast.weather.gov/newimages/medium/few.png",
      "http://forecast.weather.gov/newimages/medium/nfew.png",
      "http://forecast.weather.gov/newimages/medium/few.png",
      "http://forecast.weather.gov/newimages/medium/nfew.png",
      "http://forecast.weather.gov/newimages/medium/few.png",
      "http://forecast.weather.gov/newimages/medium/hi_ntsra20.png",
      "http://forecast.weather.gov/newimages/medium/scttsra40.png",
      "http://forecast.weather.gov/newimages/medium/hi_ntsra20.png",
      "http://forecast.weather.gov/newimages/medium/sct.png"
    ],
    "pop": [
      null,
      null,
      "40",
      "30",
      null,
      null,
      null,
      null,
      null,
      "20",
      "40",
      "20",
      null
    ],
    "temperature": [
      "65",
      "45",
      "71",
      "44",
      "63",
      "42",
      "71",
      "52",
      "78",
      "60",
      "74",
      "48",
      "66"
    ],
    "text": [
      "Sunny, with a high near 65. Calm wind becoming north northwest around 5 mph. ",
      "Mostly clear, with a low around 45. West northwest wind around 5 mph becoming calm  in the evening. ",
      "A chance of showers, with thunderstorms also possible after 5pm.  Mostly sunny, with a high near 71. Breezy, with a west southwest wind 5 to 10 mph increasing to 15 to 20 mph in the afternoon. Winds could gust as high as 25 mph.  Chance of precipitation is 40%.",
      "A chance of showers and thunderstorms before 7pm, then a slight chance of showers between 7pm and 8pm.  Mostly clear, with a low around 44. North northwest wind 10 to 15 mph.  Chance of precipitation is 30%.",
      "Sunny, with a high near 63. North wind 10 to 15 mph. ",
      "Mostly clear, with a low around 42. North wind 5 to 10 mph becoming light and variable  in the evening. ",
      "Sunny, with a high near 71. Calm wind becoming southwest around 5 mph in the afternoon. ",
      "Mostly clear, with a low around 52. South southwest wind around 5 mph. ",
      "Sunny, with a high near 78. South southwest wind 5 to 10 mph. ",
      "A 20 percent chance of showers and thunderstorms.  Partly cloudy, with a low around 60. South southwest wind 5 to 10 mph. ",
      "A 40 percent chance of showers and thunderstorms.  Partly sunny, with a high near 74. Southwest wind around 10 mph becoming north northwest in the afternoon. ",
      "A 20 percent chance of showers and thunderstorms.  Partly cloudy, with a low around 48. North northeast wind 5 to 10 mph. ",
      "Mostly sunny, with a high near 66. East southeast wind 5 to 10 mph. "
    ],
    "weather": [
      "Sunny",
      "Mostly Clear",
      "Sunny then Chance Showers and Breezy",
      "Chance Showers then Mostly Clear",
      "Sunny",
      "Mostly Clear",
      "Sunny",
      "Mostly Clear",
      "Sunny",
      "Slight Chance T-storms",
      "Chance T-storms",
      "Slight Chance T-storms",
      "Mostly Sunny"
    ]
  },
  "location": {
    "areaDescription": "3 Miles SE Robbinsdale MN",
    "county": "MNC053",
    "elevation": "886",
    "firezone": "MNZ060",
    "latitude": "45",
    "longitude": "-93.31",
    "metar": "KMIC",
    "radar": "KMPX",
    "region": "crh",
    "timezone": "C|Y|6",
    "wfo": "MPX",
    "zone": "MNZ060"
  },
  "moreInformation": "http://weather.gov",
  "operationalMode": "Production",
  "productionCenter": "Twin Cities/Chanhassen, MN",
  "srsName": "WGS 1984",
  "time": {
    "layoutKey": "k-p12h-n13-1",
    "startPeriodName": [
      "Today",
      "Tonight",
      "Tuesday",
      "Tuesday Night",
      "Wednesday",
      "Wednesday Night",
      "Thursday",
      "Thursday Night",
      "Friday",
      "Friday Night",
      "Saturday",
      "Saturday Night",
      "Sunday"
    ],
    "startValidTime": [
      "2016-05-02T06:00:00-05:00",
      "2016-05-02T18:00:00-05:00",
      "2016-05-03T06:00:00-05:00",
      "2016-05-03T18:00:00-05:00",
      "2016-05-04T06:00:00-05:00",
      "2016-05-04T18:00:00-05:00",
      "2016-05-05T06:00:00-05:00",
      "2016-05-05T18:00:00-05:00",
      "2016-05-06T06:00:00-05:00",
      "2016-05-06T18:00:00-05:00",
      "2016-05-07T06:00:00-05:00",
      "2016-05-07T18:00:00-05:00",
      "2016-05-08T06:00:00-05:00"
    ],
    "tempLabel": [
      "High",
      "Low",
      "High",
      "Low",
      "High",
      "Low",
      "High",
      "Low",
      "High",
      "Low",
      "High",
      "Low",
      "High"
    ]
  }
}
Simple.
Calling the API using .NET

// These code snippets use an open-source library. http://unirest.io/net
Task<HttpResponse<MyClass>> response = Unirest.get("https://weatherinfo.p.mashape.com/api/weather/{ip_address}")
.header("X-Mashape-Key", "{your_mashape_key}")
.header("Accept", "application/json")
.asJson();


Calling the API using Python

Doing some data analysis on your userbase? Below is a snippet of python code calling the api. You could also use urllib2 or requests, but unirest gives us a common interface across multiple languages to build these example calls.

# These code snippets use an open-source library. http://unirest.io/python
response = unirest.get("https://weatherinfo.p.mashape.com/api/weather/{ip_address}",
  headers={
    "X-Mashape-Key": "{your_mashape_key}",
    "Accept": "application/json"
  }
)


Calling the API using Objective-C

Building an iPhone app? Below is a snippet to get you started.

// These code snippets use an open-source library. http://unirest.io/objective-c
NSDictionary *headers = @{@"X-Mashape-Key": @"{your_mashape_key}", @"Accept": @"application/json"};
UNIUrlConnection *asyncConnection = [[UNIRest get:^(UNISimpleRequest *request) {
  [request setUrl:@"https://weatherinfo.p.mashape.com/api/weather/{ip_address}"];
  [request setHeaders:headers];
}] asJsonAsync:^(UNIHTTPJsonResponse *response, NSError *error) {
  NSInteger code = response.code;
  NSDictionary *responseHeaders = response.headers;
  UNIJsonNode *body = response.body;
  NSData *rawBody = response.rawBody;
}];


Calling the API using Ruby

# These code snippets use an open-source library. http://unirest.io/ruby
response = Unirest.get "https://weatherinfo.p.mashape.com/api/weather/{ip_address}",
  headers:{
    "X-Mashape-Key" => "{your_mashape_key}",
    "Accept" => "application/json"
  }


Calling the API using NodeJS
// These code snippets use an open-source library. http://unirest.io/nodejs
unirest.get("https://weatherinfo.p.mashape.com/api/weather/{ip_address}")
.header("X-Mashape-Key", "{your_mashape_key}")
.header("Accept", "application/json")
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});


Calling the API using Java

// These code snippets use an open-source library. http://unirest.io/java
HttpResponse<JsonNode> response = Unirest.get("https://weatherinfo.p.mashape.com/api/weather/{ip_address}")
.header("X-Mashape-Key", "{your_mashape_key}")
.header("Accept", "application/json")
.asJson();


Calling the API using PHP

// These code snippets use an open-source library. http://unirest.io/php
$response = Unirest\Request::get("https://weatherinfo.p.mashape.com/api/weather/{ip_address}",
  array(
    "X-Mashape-Key" => "{your_mashape_key}",
    "Accept" => "application/json"
  )
);