🚀 API Endpoints
Lấy tất cả tỉnh/thành phố
Trả về danh sách tất cả tỉnh/thành phố của Việt Nam với thông tin cơ bản
Tham số: mode
mode=0 để lấy tất cả cũ và mới
mode=1 để lấy tĩnh cũ
mode=2 để lấy tỉnh mới
Lấy quận/huyện theo tỉnh
Trả về danh sách tất cả quận/huyện thuộc một tỉnh/thành phố cụ thể. Ví dụ: provinceId=5
Lấy xã/phường theo quận/huyện
Trả về danh sách tất cả xã/phường thuộc một quận/huyện cụ thể. Ví dụ: districtId=214
Lấy xã/phường theo tỉnh (mới)
Trả về danh sách tất cả xã/phường thuộc một tỉnh/thành phố. Ví dụ: provinceId=214
💡 Ví dụ sử dụng
JavaScript (Fetch API)
// Lấy danh sách tỉnh/thành phố
fetch('https://tailieu365.com/api/address/province')
.then(response => response.json())
.then(data => {
console.log('Danh sách tỉnh/thành phố:', data);
})
.catch(error => {
console.error('Lỗi:', error);
});
// Lấy quận/huyện theo tỉnh (provinceId = 5)
fetch('https://tailieu365.com/api/address/district?provinceId=5')
.then(response => response.json())
.then(data => {
console.log('Quận/huyện:', data);
});
// Lấy xã/phường theo quận/huyện (districtId = 214)
fetch('https://tailieu365.com/api/address/ward?districtId=214')
.then(response => response.json())
.then(data => {
console.log('Xã/phường:', data);
});
Python (requests)
import requests
import json
# Lấy danh sách tỉnh/thành phố
response = requests.get('https://tailieu365.com/api/address/province')
if response.status_code == 200:
provinces = response.json()
print(json.dumps(provinces, indent=2, ensure_ascii=False))
else:
print(f'Lỗi: {response.status_code}')
# Lấy quận/huyện theo tỉnh (provinceId = 5)
response = requests.get('https://tailieu365.com/api/address/district',
params={'provinceId': 5})
districts = response.json()
print('Quận/huyện:', districts)
# Lấy xã/phường theo quận/huyện (districtId = 214)
response = requests.get('https://tailieu365.com/api/address/ward',
params={'districtId': 214})
wards = response.json()
print('Xã/phường:', wards)
cURL
# Lấy danh sách tỉnh/thành phố
curl --location 'https://tailieu365.com/api/address/province' \
--header 'Accept: application/json'
# Lấy quận/huyện theo tỉnh (provinceId = 5)
curl --location 'https://tailieu365.com/api/address/district?provinceId=5' \
--header 'Accept: application/json'
# Lấy xã/phường theo quận/huyện (districtId = 214)
curl --location 'https://tailieu365.com/api/address/ward?districtId=214' \
--header 'Accept: application/json'
# Với pretty print JSON
curl --location 'https://tailieu365.com/api/address/province' \
--header 'Accept: application/json' | jq '.'
📋 Response Format
Province List Response
[
{
"id": 10,
"name": "Yên Bái",
"isNew": null,
"newId": 94304
},
{
"id": 16,
"name": "Phú Thọ",
"isNew": null,
"newId": 94302
}
]
District List Response
[
{
"id": 797,
"name": "Huyện Lâm Bình",
"provinceId": 5
},
{
"id": 180,
"name": "Huyện Sơn Dương",
"provinceId": 5
}
]
Ward List Response
[
{
"id": 94356,
"name": "Xã Cát Hải",
"districtId": null,
"provinceId": 433,
"isNew": null,
"newId": 94301
},
{
"id": 94357,
"name": "Phường An Khê",
"districtId": null,
"provinceId": 214,
"isNew": true,
"newId": null
}
]