This topic introduces the related APIs of weather services.
API list
Request method |
API list |
Description |
GET |
/v1.0/countries/{country_code}/cities |
Query city list |
GET |
/v1.0/cities/{city_id} |
Query city information |
GET |
/v1.0/position/city |
Query city list by longitude and latitude |
GET |
/v1.0/cities/{city_id}/weather-forecast |
Query weather forecast in a city |
GET |
/v1.0/ip/weather-forecast |
Query weather forecast by the current IP address |
GET |
/v1.0/position/weather |
Query weather forecast by longitude and latitude |
GET |
/v1.0/cities/{cityId}/weathers |
Query current weather information of a city |
Query city list
Function description
Get the information of cities that support weather data in a country according to the country code.
API address
GET /v1.0/countries/{country_code}/cities
Request parameter
Parameter name |
Data type |
Parameter type |
Required |
Description |
countryCode |
String |
URI |
Yes |
Country code |
Request example
GET /v1.0/countries/cn/cities
Return message
Parameter name |
Data type |
Description |
code |
Integer |
See Error Code. |
success |
Boolean |
Whether the request succeeded or not.- true: succeeded
- false: failed
|
msg |
String |
The message returned if the request fails. It will return null if the request succeeds. |
result |
Object |
The returned result. |
Result
Parameter name |
Data type |
Description |
area |
String |
Region name |
pinyin |
String |
Region pinyin |
province |
String |
Province |
city |
String |
City name |
cityId |
String |
City ID |
Return example
{
"success": true,
"t": 1541399281296,
"result": [
{
"area": "Beijing",
"pinyin": "beijingshi",
"province": "Beijing",
"city": "Beijing",
"cityId": "793409505965772800"
},
{
"area": "Tianjin",
"pinyin": "tianjinshi",
"province": "Tianjin",
"city": "Tianjin",
"cityId": "793409507844820992"
}
]
}
Query city information
Function description
Query city information by city ID.
API address
GET /v1.0/cities/{city_id}
Request parameter
Parameter name |
Data type |
Parameter type |
Required |
Description |
city_id |
String |
URI |
Yes |
City ID |
Request example
GET /v1.0/cities/793409534348627968
Return message
Parameter name |
Data type |
Description |
code |
Integer |
See Error Code. |
success |
Boolean |
Whether the request succeeded or not.- true: succeeded
- false: failed
|
msg |
String |
The message returned if the request fails. It will return null if the request succeeds. |
result |
Object |
The returned result. |
Result
Parameter name |
Data type |
Description |
id |
String |
City information |
ids |
String |
Last update time |
dbTable |
String |
City information |
parentId |
Integer |
City information |
name |
String |
City name |
shortName |
String |
City information |
province |
String |
Province name |
countryName |
String |
Country name |
parentCityName |
String |
City information |
level |
Integer |
City information |
lon |
String |
Longitude |
lat |
String |
Latitude |
cityHash |
String |
City information |
cityIndexId |
Integer |
City information |
domesticCity |
Boolean |
City information |
Return example
{
"success": true,
"t": 1541399281296,
"result": {
"id": 79340953434862****,
"ids": null,
"gmtCreate": 1477877317000,
"gmtModified": 1477877317000,
"dbTable": null,
"parentId": 79341683897231****,
"name": "Hangzhou",
"shortName": "Hangzhou",
"province": "Zhejiang",
"countryName": "China",
"parentCityName": "Hangzhou",
"level": 3,
"lon": "120.1650798",
"lat": "30.25258003",
"cityHash": "wtmk",
"cityIndexId": 62160,
"domesticCity": true
}
}
Error code
The following are common service exceptions for this API. For more exception errors, see Error Code.
Error code |
Description |
500 |
System error |
Query city list by longitude and latitude
Function description
Query city information by longitude and latitude
API address
GET /v1.0/position/city
Request parameter
Parameter name |
Data type |
Parameter type |
Required |
Description |
lon |
String |
URL |
Yes |
Longitude |
lat |
String |
URL |
Yes |
Latitude |
Request example
GET /v1.0/position/city?lon=120.165&lat=30.252
Return message
Parameter name |
Data type |
Description |
code |
Integer |
See Error Code. |
success |
Boolean |
Whether the request succeeded or not.- true: succeeded
- false: failed
|
msg |
String |
The message returned if the request fails. It will return null if the request succeeds. |
result |
Object |
The returned result. |
Result
Parameter name |
Data type |
Description |
area |
String |
Region name |
pinyin |
String |
Region pinyin |
province |
String |
Province |
city |
String |
City name |
cityId |
Integer |
City ID |
Return example
{
"success": true,
"t": 1541401512639,
"result": {
"area": "Shangcheng",
"pinyin": "shangshangchengquou",
"province": "Zhejiang",
"city": "Hangzhou",
"cityId": 793409589986070528
}
}
Error code
The following are common service exceptions for this API. For more exception errors, see Error Code.
Error code |
Description |
500 |
System error |
Query weather forecast in a city
Function description
Query weather forecast by city ID.
API address
GET /v1.0/cities/{city_id}/weather-forecast
Request parameter
Parameter name |
Data type |
Parameter type |
Required |
Description |
city_id |
String |
URI |
Yes |
City ID |
Request example
GET /v1.0/cities/793409534348627968/weather-forecast
Return message
Parameter name |
Data type |
Description |
code |
Integer |
See Error Code. |
success |
Boolean |
Whether the request succeeded or not.- true: succeeded
- false: failed
|
msg |
String |
The message returned if the request fails. It will return null if the request succeeds. |
result |
Object |
The returned result. |
Result
Parameter name |
Data type |
Description |
year-mouth-day |
Object |
The weather forecast corresponding to the date |
Weather forecast details
Parameter name |
Data type |
Description |
condTxt |
String |
Weather overview |
tempRange |
String |
Temperature range |
updateTime |
String |
Update time |
Request example
{
"success": true,
"t": 1541402025275,
"result": {
"2018-11-07": {
"condTxt": "Light rain",
"tempRange": "16-20",
"updateTime": null
},
"2018-11-08": {
"condTxt": "Light rain",
"tempRange": "10-18",
"updateTime": null
}
}
}
Error code
The following are common service exceptions for this API. For more exception errors, see Error Code.
Error code |
Description |
500 |
System error |
Query weather forecast by IP address
Function description
Query weather forecast by the IP address of a city.
API address
GET /v1.0/ip/weather-forecast
Request parameter
Parameter name |
Data type |
Parameter type |
Required |
Description |
ip |
String |
URL |
No |
IP |
Request example
GET /v1.0/ip/weather-forecast?ip=xxx.xxx.xxx.xxx
Return message
Parameter name |
Data type |
Description |
code |
Integer |
See Error Code. |
success |
Boolean |
Whether the request succeeded or not.- true: succeeded
- false: failed
|
msg |
String |
The message returned if the request fails. It will return null if the request succeeds. |
result |
Object |
The returned result. |
Result
Parameter name |
Data type |
Description |
year-mouth-day |
Object |
The weather forecast corresponding to the date |
Weather forecast details
Parameter name |
Data type |
Description |
condTxt |
String |
|
tempRange |
String |
Temperature range |
updateTime |
String |
Update time |
Request example
{
"success": true,
"t": 1541402025275,
"result": {
"2018-11-07": {
"condTxt": "Light rain",
"tempRange": "16-20",
"updateTime": null
},
"2018-11-08": {
"condTxt": "Light rain",
"tempRange": "10-18",
"updateTime": null
}
}
}
Error code
The following are common service exceptions for this API. For more exception errors, see Error Code.
Error code |
Description |
500 |
System error |
Query weather forecast by longitude and latitude
Function description
Query weather information of a city by longitude and latitude.
API address
GET /v1.0/position/weather
Request parameter
Parameter name |
Data type |
Parameter type |
Description |
Required |
lon |
String |
URL |
Longitude |
Yes |
lat |
String |
URL |
Latitude |
Yes |
Request example
GET /v1.0/position/weather?lon=120.1650798&lat=30.25258003
Return message
Parameter name |
Data type |
Description |
code |
Integer |
See Error Code. |
success |
Boolean |
Whether the request succeeded or not.- true: succeeded
- false: failed
|
msg |
String |
The message returned if the request fails. It will return null if the request succeeds. |
result |
Object |
The returned result. |
Result
Parameter name |
Data type |
Description |
data |
Object |
City information |
lastUpdateTime |
String |
Last update time |
Data
Parameter name |
Data type |
Description |
temp |
String |
Temperature |
o3 |
String |
O3 index |
windLevel |
String |
Wind level |
pm10 |
String |
PM10 index |
uvi |
String |
Ultraviolet index |
pressure |
String |
Air pressure |
windDir |
String |
Wind direction |
co |
String |
CO index |
tips |
String |
Weather tips |
realFeel |
String |
Apparent temperature |
no2 |
String |
NO2 index |
condition |
String |
Weather conditions, such as cloudy, sunny, rainy, snowy, and more. |
pm25 |
String |
PM2.5 index |
so2 |
String |
Sulfur dioxide index |
aqi |
String |
Air quality index |
humidity |
String |
Humidity |
rank |
String |
Air quality rating |
windSpeed |
String |
Wind speed |
Return example
{
"success": true,
"t": 1541403147707,
"result": {
"data": {
"temp": "21",
"o3": "13",
"windLevel": "2",
"pm10": "53",
"uvi": "4",
"pressure": "1020",
"windDir": "East wind",
"co": "8",
"tips": "Today: Rainy. The temperature is very comfortable.",
"realFeel": "21",
"no2": "21",
"condition": "Cloudy",
"pm25": "46",
"so2": "4",
"aqi": "53",
"humidity": "78",
"rank": "393/577",
"windSpeed": "2.45"
},
"lastUpdateTime": 1541390400000
}
}
Error code
The following are common service exceptions for this API. For more exception errors, see Error Code.
Error code |
Description |
500 |
System error |
Query current weather information of a city
Function description
Query current weather information of a city by city ID.
API address
GET /v1.0/cities/{city_id}/weathers
Request parameter
Parameter name |
Data type |
Parameter type |
Required |
Description |
city_id |
String |
URI |
Yes |
City ID |
Request example
GET /v1.0/cities/793409505965772800/weathers
Return message
Parameter name |
Data type |
Description |
code |
Integer |
See Error Code. |
success |
Boolean |
Whether the request succeeded or not.- true: succeeded
- false: failed
|
msg |
String |
The message returned if the request fails. It will return null if the request succeeds. |
result |
Object |
The returned result. |
Result
Parameter name |
Data type |
Description |
temp |
String |
Temperature |
o3 |
String |
O3 index |
windLevel |
String |
Wind level |
pm10 |
String |
PM10 index |
uvi |
String |
Ultraviolet index |
pressure |
String |
Air pressure |
windDir |
String |
Wind direction |
co |
String |
CO index |
tips |
String |
Weather tips |
realFeel |
String |
Apparent temperature |
no2 |
String |
NO2 index |
condition |
String |
Weather conditions, such as cloudy, sunny, rainy, snowy, and more. |
pm25 |
String |
PM2.5 index |
so2 |
String |
Sulfur dioxide index |
aqi |
String |
Air quality index |
humidity |
String |
Humidity |
rank |
String |
Air quality rating |
windSpeed |
String |
Wind speed |
Return example
{
"result": {
"data": {
"aqi": "26",
"co": "3",
"condition": "Sunny",
"humidity": "22",
"no2": "7",
"o3": "19",
"pm10": "26",
"pm25": "11",
"pressure": "1020",
"realFeel": "19",
"so2": "1",
"temp": "19",
"tips": "Slightly cool, still comfortable.",
"uvi": "6",
"windDir": "North wind",
"windLevel": "3",
"windSpeed": "3.6"
},
"lastUpdateTime": 1585882508000
},
"success": true,
"t": 1585884424027
}
Error code
The following are common service exceptions for this API. For more exception errors, see Error Code.
Error code |
Description |
500 |
System error |