NATION

PASSWORD

NationStates API (nationdata/regiondata)

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.

Advertisement

Remove ads

User avatar
Catlander
Envoy
 
Posts: 240
Founded: Jul 01, 2017
Ex-Nation

Postby Catlander » Thu Jul 27, 2017 9:42 am

RantSpot wrote:This is a Google Sheets issue, not a NationStates issue, but... the URL needs to be in quotes.
Code: Select all
=HYPERLINK("https://www.nationstates.net/cgi-bin/api.cgi?nation=catlander&q=gdp")


Works! I just see the link.... perhaps how i can to get the value of 'gdp' into the cell?

edit: I'm still searching any google function able. This:

Code: Select all

=IMPORTXML("https://www.nationstates.net"; "/cgi.bin/api?nation=catlander&q=gdp")



I get an TRUE into the cell
Last edited by Catlander on Thu Jul 27, 2017 10:01 am, edited 1 time in total.

User avatar
RantSpot
Secretary
 
Posts: 36
Founded: Feb 15, 2010
New York Times Democracy

Postby RantSpot » Thu Jul 27, 2017 10:09 am

For the second time, this is an elementary Google Sheets question, not a NationStates question. At all. NationStates puts out some XML. It does that correctly.

To change the link to say "GDP":
Code: Select all
=HYPERLINK("https://www.nationstates.net/cgi-bin/api.cgi?nation=catlander&q=gdp","GDP")

The first argument is the full URL, the second argument is the label. Consult the Google Sheets documentation for HYPERLINK.

To fill a cell with the actual GDP value:
Code: Select all
=IMPORTXML("https://www.nationstates.net/cgi-bin/api.cgi?nation=catlander&q=gdp","//GDP")

The first argument is the XML URL, the second argument is an XPATH query. Consult the Google Sheets documentation for IMPORTXML. I expect you will also need to learn more about XPATH.

These were Google Sheets/XPATH queries. These were not NationStates API questions. This is not a forum for Google Sheets questions.

User avatar
Frisbeeteria
Senior Game Moderator
 
Posts: 27796
Founded: Dec 16, 2003
Capitalizt

Postby Frisbeeteria » Thu Jul 27, 2017 10:51 am

RantSpot wrote:These were Google Sheets/XPATH queries. These were not NationStates API questions. This is not a forum for Google Sheets questions.

^ This ^. If you continue to ask questions in inappropriate threads, you (Catlander, that is) will get warned for spamming.

User avatar
Leppikania
Minister
 
Posts: 2332
Founded: Apr 13, 2015
Left-wing Utopia

Postby Leppikania » Thu Jul 27, 2017 11:06 am

My embassy telegram script has been getting a lot of timeouts and server errors; what's going on?
INTP, -4.25 Economic Left/Right, -4.1 Social Libertarian/Authoritarian, tastes like chicken.
I do use NS stats, thank you very much.
Funny Quotes
Pie charts for industries
Request an Embassy

User avatar
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Fri Jul 28, 2017 9:29 pm

Leppikania wrote:My embassy telegram script has been getting a lot of timeouts and server errors; what's going on?

What is your script's user agent?
Frisbeeteria wrote:
RantSpot wrote:These were Google Sheets/XPATH queries. These were not NationStates API questions. This is not a forum for Google Sheets questions.

^ This ^. If you continue to ask questions in inappropriate threads, you (Catlander, that is) will get warned for spamming.

That being said, while you are here, please also add "&script=something_identifying_your_spreasdheet" to the end of the URL in your IMPORTXML call. I know you can't set a user agent in google sheets, but you must still identify yourself to us.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Leppikania
Minister
 
Posts: 2332
Founded: Apr 13, 2015
Left-wing Utopia

Postby Leppikania » Sun Jul 30, 2017 12:42 pm

Eluvatar wrote:
Leppikania wrote:My embassy telegram script has been getting a lot of timeouts and server errors; what's going on?

What is your script's user agent?

It's a generic user agent; the script is identified through the "script" URL parameter, which is "Embassy Telegram 2.0".
INTP, -4.25 Economic Left/Right, -4.1 Social Libertarian/Authoritarian, tastes like chicken.
I do use NS stats, thank you very much.
Funny Quotes
Pie charts for industries
Request an Embassy

User avatar
Trotterdam
Postmaster-General
 
Posts: 10541
Founded: Jan 12, 2012
Left-Leaning College State

Postby Trotterdam » Sun Jul 30, 2017 12:52 pm

I'm pretty sure your identification, wherever it's put, is supposed to include something personal that can be used to contact you, like your nation name or email address.

User avatar
RantSpot
Secretary
 
Posts: 36
Founded: Feb 15, 2010
New York Times Democracy

Postby RantSpot » Tue Aug 01, 2017 11:11 am

Some other API questions/requests:

Is there any circumstance in which a ping request will receive a PING response other than 1? If there's an error, it seems there would not be a reply (HTTP response code other than 200, no XML response content). Are there ever PINGs of 0 or anything else !=1?

About the 50 requests in 30 seconds (or .6 second delay) rate limit:
  • Will the server implement this automatically?
  • I assume it applies to public, private, and TG shards, and applies per request not per shard
  • Does it apply to request times or responses? That is, if I make requests uniformly .6 seconds after the last (including delay waiting for a response), should I be safe?
  • The documentation implies it's a per-IP rate limit, but that spreading requests across IPs and agents would be detected. I assume that third-party public shard requests wouldn't impact users' ability to request public and private shards, especially since users can't necessarily control public shard API calls for their nations, even from tools they might use (e.g. Google Sheets)
  • Some of these answers and details would do well in the API documentation

There should be samples or details of private shard contents in the API documentation. Just clicking the link works for the public shards, but obviously not the private. It's not hard to figure out what each does and how they respond, but that would be good to include in documentation for clarity. A brief explanation of what some things are (like DBID) could be useful for those not intimately familiar with all the functions; in fact, such brief description could be produced and offered (in spoiler tags, on a details page, however) for all available calls. I'd be happy to contribute to a documentation enhancement. It's already helpfully offered for census and banners shards.

Could it be possible to join nation requests as it currently is shard requests? (i.e. nation=testlandia+maxtopia&q=gdp+population) It's already fairly trivial to request data for multiple nations and merge them (e.g. into one XML list with multiple NATION items), but being able to consolidate them would reduce the number of necessary requests, which should somewhat reduce bandwidth load (though I don't know how it would impact the server overall).

Sorry to be such a bother and toss so many questions/thoughts out at once. Just passing along what I encounter while developing/playing with the API.
Last edited by RantSpot on Tue Aug 01, 2017 11:12 am, edited 1 time in total.

User avatar
Greater Tern
Envoy
 
Posts: 331
Founded: Mar 04, 2010
Civil Rights Lovefest

Postby Greater Tern » Tue Aug 01, 2017 12:20 pm

RantSpot wrote:About the 50 requests in 30 seconds (or .6 second delay) rate limit:
  • Will the server implement this automatically?


You have to implement a rate limiter yourself. The server locks you out for 15 minutes if you violate this limit.

RantSpot wrote:
  • I assume it applies to public, private, and TG shards, and applies per request not per shard


Yes.

RantSpot wrote:
  • The documentation implies it's a per-IP rate limit, but that spreading requests across IPs and agents would be detected. I assume that third-party public shard requests wouldn't impact users' ability to request public and private shards, especially since users can't necessarily control public shard API calls for their nations, even from tools they might use (e.g. Google Sheets)


I think the point of that rule is to prevent one user from distributing their requests across multiple IPs to avoid the rate limit. Third-party users using the same tool should be fine.

User avatar
Phydios
Minister
 
Posts: 2569
Founded: Dec 06, 2014
Left-Leaning College State

Postby Phydios » Tue Aug 01, 2017 12:51 pm

RantSpot wrote:About the 50 requests in 30 seconds (or .6 second delay) rate limit

For the record, the rate limit is not 1 request per .6 seconds. You're welcome to do your requesting in spurts.
[violet] wrote:
Imperium Anglorum wrote:Also, if my calculations are correct, the rate limit is 0.6 seconds per request?

No. It's currently 50 requests per 30 seconds, which isn't the same thing. You can make 50 requests in 1s if you make none for the next 29s.

Rate limit doc is here.
If you claim to be religious but don’t control your tongue, you are fooling yourself, and your religion is worthless. Pure and genuine religion in the sight of God the Father means caring for orphans and widows in their distress and refusing to let the world corrupt you. | Not everyone who calls out to me, ‘Lord! Lord!’ will enter the Kingdom of Heaven. Only those who actually do the will of my Father in heaven will enter. On judgment day many will say to me, ‘Lord! Lord! We prophesied in your name and cast out demons in your name and performed many miracles in your name.’ But I will reply, ‘I never knew you. Get away from me, you who break God’s laws.’
James 1:26-27, Matthew 7:21-23

User avatar
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Tue Aug 01, 2017 4:33 pm

RantSpot wrote:Is there any circumstance in which a ping request will receive a PING response other than 1? If there's an error, it seems there would not be a reply (HTTP response code other than 200, no XML response content). Are there ever PINGs of 0 or anything else !=1?

No.

RantSpot wrote:About the 50 requests in 30 seconds (or .6 second delay) rate limit:
  • Will the server implement this automatically?
  • I assume it applies to public, private, and TG shards, and applies per request not per shard
  • Does it apply to request times or responses? That is, if I make requests uniformly .6 seconds after the last (including delay waiting for a response), should I be safe?
  • The documentation implies it's a per-IP rate limit, but that spreading requests across IPs and agents would be detected. I assume that third-party public shard requests wouldn't impact users' ability to request public and private shards, especially since users can't necessarily control public shard API calls for their nations, even from tools they might use (e.g. Google Sheets)
  • Some of these answers and details would do well in the API documentation

The API doc is pretty clear in the Rate Limits section already, I'd say. It's not long and explicitly answers most of your questions above, like limits applying per request not per shard, it's 50 reqs per 30 seconds (not 0.6s per request), applied server-side, etc.

I'm not sure exactly what you mean by "third-party public shard requests," but it sounds like it's covered by Terms of Use #2: "Do Not Sneakily Exceed Rate Limits." That is, it would not be nice to run a tool from your own IP using 100% of your available ratelimit while simultaneously running another tool via Google Sheets that also made requests from another IP. But this isn't something that would be automatically detected; it would require an admin to figure it out and decide what to do about it.

RantSpot wrote:There should be samples or details of private shard contents in the API documentation. Just clicking the link works for the public shards, but obviously not the private. It's not hard to figure out what each does and how they respond, but that would be good to include in documentation for clarity. A brief explanation of what some things are (like DBID) could be useful for those not intimately familiar with all the functions; in fact, such brief description could be produced and offered (in spoiler tags, on a details page, however) for all available calls. I'd be happy to contribute to a documentation enhancement. It's already helpfully offered for census and banners shards.

Now this is true, and I'd gratefully accept better docs on each shard, since, as you say, at the moment you basically have to figure out what data you're likely to get returned by trying it.

RantSpot wrote:Could it be possible to join nation requests as it currently is shard requests?

It's not possible currently. See previous discussion in this thread e.g. here & here.

User avatar
Werreales
Envoy
 
Posts: 279
Founded: Nov 28, 2014
Ex-Nation

Postby Werreales » Fri Aug 25, 2017 1:22 pm

Hello, would it be possible to implement additional public shards regarding N-Day? For example, the following regional shards: targeted, launched and destroyed.

Thank you :)

(Note: the NS website does not support CORS policy. Will it be implemented in the future?)
Last edited by Werreales on Fri Aug 25, 2017 6:49 pm, edited 1 time in total.

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Sat Aug 26, 2017 12:21 am

Request

Would it be possible to provide a World Assembly API call that gives you the list of all individual nations voting FOR or AGAINST the current resolution at vote?

I am trying to track the votes of individual WA nations within my region, in order to let each nation browse their voting history, as well as for analysis and statistics of our "get out the vote" campaigns.

However, it is proving very cumbersome to track this information from happenings. This is because of a very large number of corner cases that one needs to take into account (resolutions with the same name submitted right after another, nations withdrawing and re-voting, having to search voting happenings by a resolution's name and then cross-reference that with the resolution's start/end timestamp, and so on).

While not impossible to do, all of this would be greatly simplified if you could add the API call I suggested. It could be something like:

Code: Select all
https://www.nationstates.net/cgi-bin/api.cgi?wa=(council_id)&q=nationvotes


This would return two fields, NATIONVOTES_FOR and NATIONVOTES_AGAINST. Each of them would have a comma-separated list of the names of nations that are currently voting FOR or AGAINST the current resolution at vote in the corresponding WA council.

Thanks in advance!

User avatar
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Sat Aug 26, 2017 2:33 pm

Werreales wrote:Hello, would it be possible to implement additional public shards regarding N-Day? For example, the following regional shards: targeted, launched and destroyed.

Yes, there will be an N-Day API. Details to come in the next few days.

User avatar
Imperium Anglorum
GA Secretariat
 
Posts: 12659
Founded: Aug 26, 2013
Left-Leaning College State

Postby Imperium Anglorum » Sat Aug 26, 2017 8:23 pm

HMS Unicorn wrote:

I absolutely second this request. It would be a fantastic addition to the game!

Author: 1 SC and 56+ GA resolutions
Maintainer: GA Passed Resolutions
Developer: Communiqué and InfoEurope
GenSec (24 Dec 2021 –); posts not official unless so indicated
Delegate for Europe
Elsie Mortimer Wellesley
Ideological Bulwark 285, WALL delegate
Twice-commended toxic villainous globalist kittehs

User avatar
Roavin
Admin
 
Posts: 1777
Founded: Apr 07, 2016
Democratic Socialists

Postby Roavin » Fri Sep 01, 2017 4:58 am

Yay on an N-Day API! \o/

Another topic: I'd like to implement a small RMB-Messenger application. Currently, that's not possible without a little bit of scraping, but I think for the requirements I currently have, it'd suffice to have a private shard giving the ID of the last read RMB message for a nation. Posting or liking would be done using the normal POST calls (respecting that these are restricted actions and handling those accordingly of course).
Helpful Resources: One Stop Rules Shop | API documentation | NS Coders Discord
About me: Longest serving Prime Minister in TSP | Former First Warden of TGW | aka Curious Observations

Feel free to TG me, but not about moderation matters.

User avatar
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Sat Sep 02, 2017 6:12 am

Would you be expecting API requests for RMB posts to affect the last read RMB post private shard?
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Trotterdam
Postmaster-General
 
Posts: 10541
Founded: Jan 12, 2012
Left-Leaning College State

Postby Trotterdam » Sat Sep 02, 2017 11:44 am

Eluvatar wrote:Would you be expecting API requests for RMB posts to affect the last read RMB post private shard?
RMB posts are public. So long as you retrieve them without logging in, which is easy for an API, they shouldn't affect any private shards, right?

User avatar
Roavin
Admin
 
Posts: 1777
Founded: Apr 07, 2016
Democratic Socialists

Postby Roavin » Sat Sep 02, 2017 12:19 pm

Eluvatar wrote:Would you be expecting API requests for RMB posts to affect the last read RMB post private shard?


I wouldn't, for the reason Trotterdam stated - retrieving RMB posts is not a private shard and therefore can't (and shouldn't) affect any associated nation. This is important particularly for the app I have in mind, which deals with multiple nations and may operate on two or more nations in the same region. On the other hand, a private shard to reset (or rather, set) the last-read counter would be quite useful. If this is done through an explicit call to do so or implicitly by requesting RMB posts with authentication is a matter of taste I guess (the former would be "cleaner", the latter more convenient for several kinds of apps though not necessarily mine).
Helpful Resources: One Stop Rules Shop | API documentation | NS Coders Discord
About me: Longest serving Prime Minister in TSP | Former First Warden of TGW | aka Curious Observations

Feel free to TG me, but not about moderation matters.

User avatar
Onderkelkia
Diplomat
 
Posts: 998
Founded: Aug 13, 2006
Corporate Police State

Postby Onderkelkia » Sat Sep 02, 2017 3:17 pm

HMS Unicorn wrote:Request

Would it be possible to provide a World Assembly API call that gives you the list of all individual nations voting FOR or AGAINST the current resolution at vote?

I am trying to track the votes of individual WA nations within my region, in order to let each nation browse their voting history, as well as for analysis and statistics of our "get out the vote" campaigns.

However, it is proving very cumbersome to track this information from happenings. This is because of a very large number of corner cases that one needs to take into account (resolutions with the same name submitted right after another, nations withdrawing and re-voting, having to search voting happenings by a resolution's name and then cross-reference that with the resolution's start/end timestamp, and so on).

While not impossible to do, all of this would be greatly simplified if you could add the API call I suggested. It could be something like:

Code: Select all
https://www.nationstates.net/cgi-bin/api.cgi?wa=(council_id)&q=nationvotes


This would return two fields, NATIONVOTES_FOR and NATIONVOTES_AGAINST. Each of them would have a comma-separated list of the names of nations that are currently voting FOR or AGAINST the current resolution at vote in the corresponding WA council.

Thanks in advance!

I would also be interested in this feature, is there any chance that the admins would implement it?"
Emperor Emeritus of The Land of Kings and Emperors
King Emeritus of Norwood, etc.

Duke of Roskilde, of Balder

Archduke of Niso, of the LKE
Archduke, of The New Inquisition
Viscount, of Great Britain and Ireland
Honoured Citizen of Europeia
Emperor of the LKE
LKE Prime Minister
LKE Chief of the Imperial General Staff

Crown Prince of TNI
Commander of TNI Armed Forces
Director General of TNI Intelligence

Vice Delegate and Crown Prince of Balder
Prince of Jomsborg
Balder Statsminister
Balder Chief of Defence

GB&I Home Secretary
GB&I First Sea Lord

Chief Justice of Europeia

Member, Imperial Military Council, UIAF
Supreme Allied Commander, SRATO

WA Delegate of The Rejected Realms

User avatar
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Sun Sep 03, 2017 5:05 pm

HMS Unicorn wrote:Would it be possible to provide a World Assembly API call that gives you the list of all individual nations voting FOR or AGAINST the current resolution at vote?

This is now available as the WA API shard "voters".

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Sun Sep 03, 2017 5:18 pm

Terrific, thanks!

User avatar
Greater Tern
Envoy
 
Posts: 331
Founded: Mar 04, 2010
Civil Rights Lovefest

Postby Greater Tern » Wed Sep 20, 2017 6:03 pm

Hey [v], can we get the edited timestamp on the RMB API? Thanks a bunch!

User avatar
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Wed Sep 20, 2017 9:23 pm

Greater Tern wrote:Hey [v], can we get the edited timestamp on the RMB API? Thanks a bunch!

Done!

User avatar
Aurum Raider
Envoy
 
Posts: 239
Founded: Sep 18, 2014
Iron Fist Consumerists

Postby Aurum Raider » Sat Sep 23, 2017 11:06 am

On the Nation Data Dump, could the <INFLUENCE> tag be altered to have an attribute containing the SPDR stat, a la <INFLUENCE spdr="23">?
Vleerian Vytherov-Denral
Cognitohazard

The North Polish Union wrote:Additionally, virtually all founderless regions are viewed as falling under the defenders' allegedly protective purview. This is a form of colonialism that the great imperialist regions of NS history could only dream of.

PreviousNext

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Daco-Romanian Federation, Emus and Papayas, Ioudaia, Lord Shabazz, Nartic Federation, Planetary Soviet Socialist Republics, South Newlandia, Super Awesome Fun Times, The Wasp Nest, Thorn1000, Veralann

Advertisement

Remove ads