Countries - State information based on country code

Guest

Countries

Get information about countries.

GET /v2/countries/states
Plus Premium Professional Enterprise

State information based on country code

Allows you to retrieve information about states of a specific country using the country code. This functionality is ideal for applications that require geographic detail at the state level.

GET https://zip-api.eu/api/v2/countries/states?countryCode=...
  • JavaScript
  • cURL
  • Python
  • PHP
  • Java
  • C#
const url = "https://zip-api.eu/api/v2/countries/states?countryCode=AT";

fetch(url, {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY'
  }
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
curl -X GET "https://zip-api.eu/api/v2/countries/states?countryCode=AT" \
     -H "Authorization: Bearer YOUR_API_KEY"
import requests

url = "https://zip-api.eu/api/v2/countries/states?countryCode=AT"
headers = {
    "Authorization": "Bearer YOUR_API_KEY"
}

response = requests.get(url, headers=headers)

if response.status_code == 200:
    print(response.json())
else:
    print(f"Error: {response.status_code}")
$url = "https://zip-api.eu/api/v2/countries/states?countryCode=AT";

// Initialize cURL session
$ch = curl_init();

// Set options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY'
]);

// Execute the request
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    echo $response;
}

// Close the cURL session
curl_close($ch);
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class ApiRequest {
    public static void main(String[] args) {
        try {
            String url = "https://zip-api.eu/api/v2/countries/states?countryCode=AT";
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            // Request setup
            con.setRequestMethod("GET");
            con.setRequestProperty("Authorization", "Bearer YOUR_API_KEY");

            // Get response code
            int responseCode = con.getResponseCode();
            System.out.println("Response Code : " + responseCode);

            // Read the response
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            // Print the response
            System.out.println(response.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    private static readonly HttpClient client = new HttpClient();

    static async Task Main(string[] args)
    {
        string url = "https://zip-api.eu/api/v2/countries/states?countryCode=AT";

        // Add authorization header
        client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");

        // Send GET request
        HttpResponseMessage response = await client.GetAsync(url);

        // Check the status code and get the response content
        if (response.IsSuccessStatusCode) {
            string responseBody = await response.Content.ReadAsStringAsync();
            Console.WriteLine(responseBody);
        } else {
            Console.WriteLine("Error: " + response.StatusCode);
        }
    }
}

Header

API-Key string - required
Bearer token for authentication.

Query Parameters

GET countryCode string - required

Two-letter country code (Alpha-2 code) defined in ISO 3166-1.

Response Parameters

state string

The geographical name of the state or province.

Status codes

200 Standard response for successfully processed requests
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
405 Method Not Allowed
409 Conflict
413 Request Entity Too Large
429 Too Many Requests
500 Internal Server Error