National Weather Service API
api.weather.gov · Government
Official US National Weather Service API — forecasts, alerts, observations, radar stations, and zone data. Free, no API key required. Covers USA only.
Authentication
No authentication requiredFree to use with no key needed.
Sample Requests
GET
Get forecast for coordinates
Get forecast office and grid coordinates for a lat/lon point.
https://api.weather.gov/points/39.7456,-97.0892
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| User-Agent | (myapp, [email protected]) |
curl -X GET "https://api.weather.gov/points/39.7456,-97.0892" \ -H "User-Agent: (myapp, [email protected])"
import requests
headers = {
"User-Agent": "(myapp, [email protected])"
}
response = requests.get(
"https://api.weather.gov/points/39.7456,-97.0892",
headers=headers,
)
print(response.json())const url = 'https://api.weather.gov/points/39.7456,-97.0892';
const response = await fetch(url, {
headers: {
'User-Agent': '(myapp, [email protected])'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
)
func main() {
targetURL := "https://api.weather.gov/points/39.7456,-97.0892"
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("User-Agent", "(myapp, [email protected])")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.weather.gov/points/39.7456,-97.0892")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["User-Agent"] = "(myapp, [email protected])"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.weather.gov/points/39.7456,-97.0892";
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"User-Agent: (myapp, [email protected])"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
Get active alerts
Get all active weather alerts for Texas.
https://api.weather.gov/alerts/active?area=TX
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| User-Agent | (myapp, [email protected]) |
curl -X GET "https://api.weather.gov/alerts/active?area=TX" \ -H "User-Agent: (myapp, [email protected])"
import requests
params = {
"area": "TX"
}
headers = {
"User-Agent": "(myapp, [email protected])"
}
response = requests.get(
"https://api.weather.gov/alerts/active",
params=params,
headers=headers,
)
print(response.json())const url = new URL('https://api.weather.gov/alerts/active');
url.searchParams.set('area', 'TX');
const response = await fetch(url, {
headers: {
'User-Agent': '(myapp, [email protected])'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.weather.gov/alerts/active")
q := baseURL.Query()
q.Set("area", "TX")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("User-Agent", "(myapp, [email protected])")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.weather.gov/alerts/active")
uri.query = URI.encode_www_form({
"area" => "TX"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["User-Agent"] = "(myapp, [email protected])"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.weather.gov/alerts/active?" . http_build_query([
"area" => "TX"
]);
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"User-Agent: (myapp, [email protected])"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- No API key needed
- Always set User-Agent header: (yourapp.com, [email protected])
- Step 1: Get grid point: GET /points/{lat},{lon}
- Step 2: Use the forecast URL from the response to get the forecast
- Alerts: GET /alerts/active?area=CA for California