Country Flag API

The Country Flag API provides SVG flag images for any country, territory, or area of special interest (over 250 supported). The small file sizes are perfect for displaying flag icons on your website or populating a dropdown menu.

For a list of all countries, see the /v1/allcountryflags endpoint.

For geographic, demographic and economic statistics on countries, check out the Country API instead.

/v1/countryflag GET

https://api.api-ninjas.com/v1/countryflag

Get a country's flag as an SVG image in base64 format. Both 1:1 and 4:3 aspect ratios are supported and returned in the response.


Parameters

  • country  required

    2-letter ISO-3166 alpha-2 country code (e.g. US, CA, FR). For countries in the United Kingdom, use GB for Great Britain, GB-ENG for England, GB-SCT for Scotland, GB-WLS for Wales, GB-NIR for Northern Ireland.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Sample Request Live Demo!

country
https://api.api-ninjas.com/v1/countryflag?country=US

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
1 2 3 4 5 { "country": "US", "square_image_url": "https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/1x1/KoHP0ZTO/us.svg", "rectangle_image_url": "https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/4x3/8L07WqeX/us.svg" }

Code Examples

1 2 3 4 5 6 7 8 9 import requests country = 'US' api_url = 'https://api.api-ninjas.com/v1/countryflag?country={}'.format(country) response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'}) if response.status_code == requests.codes.ok: print(response.text) else: print("Error:", response.status_code, response.text)

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.

/v1/allcountryflags GETPremium Only

https://api.api-ninjas.com/v1/allcountryflags

Get flag images for all countries. Returns an list of countries and their flag URLs.


Headers

  • X-Api-Key  required

    API Key associated with your account.

Sample Request

https://api.api-ninjas.com/v1/allcountryflags

Sample Response

JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 [ { "country": "AD", "square_image_url": "https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/1x1/irDOqrgs/ad.svg", "rectangle_image_url": "https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/4x3/kSezcqOa/ad.svg" }, { "country": "AE", "square_image_url": "https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/1x1/5RmaAls3/ae.svg", "rectangle_image_url": "https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/4x3/g2IOl3w9/ae.svg" }, ... ]