1

I tried using this link: https://api.worldbank.org/v2/state/NE/indicator/SP.POP.TOTL?date=2021

and it says that the endpoint is not found ... please give me a link that will work using the worldbank api to get the info by a specific state. Please and thank you.

3 Answers 3

1

The endpoint you're using is incorrect, you have to replace state by country in the URL, as explained in the API documention. In your case, the correct URL is:

https://api.worldbank.org/v2/country/NE/indicator/SP.POP.TOTL?date=2021

This is a request for the population of Niger, whose alpha-2 code is NE. If you were looking for the US state of Nebraska, as far as I know the WorldBank does not provide data about it. In this case, you'd have to look at other sources.

Now, if you're really looking for the data of all countries, downloading a dump as suggested by @IvanBegtin may be the most optimal solution for you and for the World Bank servers (see their recommendations for querying their API: https://datahelpdesk.worldbank.org/knowledgebase/articles/902064-development-best-practices ).

Alternatively, you could query the API for getting the data of all countries, using all instead of a country code (e.g., https://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?date=2021). However, by default the results are limited to 50 by request. So to get all the data, you'll have to run multiple queries or to use the per_page argument as explained in their documentation (e.g. https://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?date=2021&per_page=300 to get 300 results per query). Again, beware of their recommendations for querying the API, to avoid putting too much strain on their servers.

1

If you are writing about states as countries, you could get all all data for all countries using single call. Here are links to XML and CSV datasets https://data.worldbank.org/indicator/SP.POP.TOTL

0

Please visit https://www.census.gov/library/visualizations/interactive/how-has-our-nations-population-changed.html and grep "Total Population" from the csv. Does that not answer your per-state population query?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.