The NationStates API allows external sites to collect data about NS regions and nations. You can access it via your own scripts to gather information and produce your own reports or analysis.
There are four ways to get data:
http://www.nationstates.net/cgi-bin/api.cgi/nation=XXXX
... where XXXX is the name of a nation. To be valid when sent via HTTP, spaces in nation names should be changed to underscores (e.g. the_grendels), or represented as %20. Names are not case-sensitive.
http://www.nationstates.net/cgi-bin/api.cgi/region=XXXX
... where XXXX is the name of a region. Spaces should be encoded as above. Names are not case-sensitive.
If you need data on every nation and/or region in the game, don't request them one at a time from the API. Instead, download a daily dump file, which contains all of the XML in a single file. These are generated once per day at around 22:30 PDT. They are fairly large (approx. 1MB for regions and 7MB for nations) and compressed with gzip.
http://www.nationstates.net/pages/regions.xml.gz
http://www.nationstates.net/pages/nations.xml.gz
Some people use a combination of API calls and dump files. For example, they will download the dumps once per day to compile their stats, then, if a user requests info on a particular nation or region, make one or two API calls to refresh the data on that so it's up-to-the-second.
Complete lists of all regions/nations. Please note this information is now available from the Daily Data Dumps, so there is probably no good reason to use this any more. It may be removed in the future.
http://www.nationstates.net/cgi-bin/api.cgi?allregions=1
http://www.nationstates.net/cgi-bin/api.cgi?allnations=1
The API is rate-limited and will temporarily lock you out if you send too many requests within a short period of time. (And return status 421: "Too Many Requests From Your IP Address.") If you need to gather information on very large numbers of nations or regions, you should use a Daily Data Dump, not send dozens or hundreds of API queries all at once.
Rate Limit of Nation & Region APIs: 50 requests per 30 seconds. Traffic exceeding this rate will be temporarily banned (for around 15 minutes), so please try to stay well within it. It is usually not feasible to gather data from the APIs on every nation in a region all at once: if you want to do this, you should download a Daily Data Dump once per day and use the data from this instead.
Rate Limit of Daily Data Dumps: Not auto-limited, but there is no need to download each dump more than once per day, as the data doesn't change. Scripts that request these files too frequently will be permanently banned.
Rate Limit of Name Lists: Not auto-limited, but the lists update only twice per day (during daily updates), so should not be queried frequently. Scripts that disobey will be permanently banned.
If possible, please set your script's UserAgent to something informative, such as the URL of your site. This will allow us to contact you if something goes wrong with your script, rather than simply banning it.
Discussion about the API and related tools takes place in the Technical Forum.
Some sites using the NationStates API: