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
Imperium Anglorum
GA Secretariat
 
Posts: 12664
Founded: Aug 26, 2013
Left-Leaning College State

Postby Imperium Anglorum » Thu Aug 11, 2016 1:09 pm

Caelapes wrote:reset the CTE-by-inactivity timer?

I too would like to know this.

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
Trotterdam
Postmaster-General
 
Posts: 10545
Founded: Jan 12, 2012
Left-Leaning College State

Postby Trotterdam » Thu Aug 11, 2016 2:32 pm

If it updates the "Most Recent Government Activity" timer then it probably prevents CTEs.

What's the time limit for non-PIN logins? Currently it just says "within a few seconds".

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

Postby [violet] » Thu Aug 11, 2016 4:14 pm

Flanderlion wrote:using this to view the data, then using the nation pages to actually execute the operations wouldn't be more efficient timewise for me yet, despite the higher rate limits for API.

The next step after filling out the private shards will be to add an API that lets you make changes to nations, like answering issues, rather than just gathering information about them. Long-term, I aim to migrate all script/bot activity to the API, which would provide several advantages for us and legal scripters.

Flanderlion wrote:Also for just clicking the link (in browser) from my logged in nation, would it be able to appear authenticated so you can view what you'd get for yourself.

Unfortunately no, as this would make the API vulnerable to XSS attacks using your cookies. You need to use headers.

Caelapes wrote:Does accessing a private shard reset the CTE-by-inactivity timer?

Yes.

Trotterdam wrote:What's the time limit for non-PIN logins? Currently it just says "within a few seconds".

Currently you get a 409 Conflict error from the API if you attempt to authenticate via Password or Autologin within 6 seconds of a previous successful login. The exact time period will change, though. It will never be higher than 30 seconds.

User avatar
Flanderlion
Minister
 
Posts: 2228
Founded: Nov 25, 2013
Psychotic Dictatorship

Postby Flanderlion » Fri Aug 12, 2016 1:12 am

[violet] wrote:
Flanderlion wrote:using this to view the data, then using the nation pages to actually execute the operations wouldn't be more efficient timewise for me yet, despite the higher rate limits for API.

The next step after filling out the private shards will be to add an API that lets you make changes to nations, like answering issues, rather than just gathering information about them. Long-term, I aim to migrate all script/bot activity to the API, which would provide several advantages for us and legal scripters.

Flanderlion wrote:Also for just clicking the link (in browser) from my logged in nation, would it be able to appear authenticated so you can view what you'd get for yourself.

Unfortunately no, as this would make the API vulnerable to XSS attacks using your cookies. You need to use headers.

Caelapes wrote:Does accessing a private shard reset the CTE-by-inactivity timer?

Yes.

This sounds very useful. We will get a grace period to move things over to the new action API right when it comes out?

So accessing the private shard is just like logging in, there isn't any cons to it (except for atm. you can't do any actions with it, just collect info that a normal autologin script can do).

Also, had no clue about XSS attacks before this (bar a vague idea).
As always, I'm representing myself.
Information
Wishlist

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

Postby [violet] » Fri Aug 12, 2016 8:05 pm

Flanderlion wrote:
[violet] wrote:Long-term, I aim to migrate all script/bot activity to the API, which would provide several advantages for us and legal scripters.

We will get a grace period to move things over to the new action API right when it comes out?

Yes, it will be long slow move, if it happens at all.

User avatar
Caelapes
Ambassador
 
Posts: 1543
Founded: Apr 30, 2007
Ex-Nation

Postby Caelapes » Sat Aug 13, 2016 8:14 am

[violet] wrote:
Flanderlion wrote:We will get a grace period to move things over to the new action API right when it comes out?

Yes, it will be long slow move, if it happens at all.

I assume that since this will eventually allow users to make changes to their nations through the API (and also apparently counts as a log-in -- does it show that it's an API login and not a front-end login in the moderator panel/however you check nations' IP addresses?), that there is a recommendation against sharing PINs and especially autologins for the purposes of allowing other users to run puppet-maintaining scripts?
    
The Rose Commune of Caelapes
Ego vero custos fratris mei sum.
aka Misley

User avatar
The United Island Tribes
Bureaucrat
 
Posts: 48
Founded: Oct 17, 2014
Left-wing Utopia

Bug Report

Postby The United Island Tribes » Sun Aug 14, 2016 10:23 am

I believe PIN for private shards is not working as described.

When I was implementing authentication for my library, I noticed the PIN seemed to have wrongly behaved the same way as Password and AutoLogin in some cases.

I noticed this when I was looking at my issues (Being logged in at the same time does work, howevver) in my browser at the same time the test script was running. While I might understand why this would cause a forbidden error (Viewing issues may require login verification that would reset the Pin), it actually returns a conflict error (409).
The documentation implies that Pins should not get conflict errors (Only 403 forbidden errors when the PIN is reset), so I am not sure if this an error or intended behavior.

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

Postby [violet] » Sun Aug 14, 2016 3:44 pm

The United Island Tribes wrote:The documentation implies that Pins should not get conflict errors

This is correct: You can't get a 409 Conflict error from a valid Pin. You can, however, get a 409 if you send an expired Pin along with a Password or Autologin header, since that will fallback to a new login attempt, as per the flowchart diagram in the API doc.

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

Postby [violet] » Sun Aug 14, 2016 3:50 pm

Caelapes wrote:I assume [...] there is a recommendation against sharing PINs and especially autologins for the purposes of allowing other users to run puppet-maintaining scripts?

Yes, from a moderation point of view, you are responsible for your account, even if you give someone else your login credentials and they misuse them.

User avatar
Nationstates API Test Nation
Civilian
 
Posts: 1
Founded: Jul 17, 2016
Ex-Nation

Postby Nationstates API Test Nation » Mon Aug 15, 2016 6:27 am

[violet] wrote:
The United Island Tribes wrote:The documentation implies that Pins should not get conflict errors

This is correct: You can't get a 409 Conflict error from a valid Pin. You can, however, get a 409 if you send an expired Pin along with a Password or Autologin header, since that will fallback to a new login attempt, as per the flowchart diagram in the API doc.


I will look into this, however I do not believe my script the password with the PIN. It instead catches a 403 error and sends a request with the password/autologin

EDIT: This nation is a test nation The United Island Tribes
Last edited by Nationstates API Test Nation on Mon Aug 15, 2016 6:29 am, edited 1 time in total.

User avatar
Atagait Denral
Secretary
 
Posts: 40
Founded: Jun 02, 2015
Ex-Nation

Postby Atagait Denral » Fri Aug 19, 2016 12:28 pm

I found an incredibly handy work-around for getting delegate information via the API. It turns out polling all 19,131 regions isn't necessary. You can cut out all founderless regions, password regions, and class regions. Rather than taking 10 hours of requesting region data every 2 seconds, it neatly cuts it in half where you only have to spend about 5 hours.

It's still an absolutely absurd amount of time... but gotta get those non-exec founders somehow, amiright?
Last edited by Atagait Denral on Fri Aug 19, 2016 12:28 pm, edited 1 time in total.
Vleerian Vytherov
Script Writer

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

Postby HMS Unicorn » Fri Aug 19, 2016 2:41 pm

[violet] wrote:I've added "Private Shards," for when you want to access information that's only available to a logged-in nation.

For now the only shard is "unread", which will tell you how many new TGs, Issues, etc, you have. But I aim to expand it in the future to cover telegrams, issues, and more. So please give this a test and let me know what you think.

For details see "Private Shards" in the API doc!

Late to the show, but I just got the chance to play with this.

Thanks for making this, very interesting change. I've been considering requesting some kind of "private" API calls for a while now, but I always thought it'd be very unlikely they'd be implemented, given how the API has always been strictly limited to public information.

I've moved my puppet management script to the API.

Since you've also asked for ideas about things to add to the private API, here are some suggestions. These correspond to tasks I currently have to do by making game-side calls to log into the nation and perform actions from there:

1) Getting a list of IDs for all the telegrams a nation has in their Sent folder.
2) Using the above IDs, getting details for each such telegram (text, creation date, recruitment/campaign/regionwide/welcoming classification, template or API classification, list of recipients or delivery reports).
3) Creating new telegram templates or API templates for that nation (obviously *not* sending them, unless it is through the telegram API).
4) Editing pre-existing factbooks and dispatches owned by that nation (note that this is not the same as creating new dispatches with that nation).

I currently use 1-2 to automatically monitor the success rates of recruitment telegrams and periodically produce reports, graphs etc.

I do not do 3, but it would be helpful for automatically updating telegram templates that reference, say, region officials etc. that tend to change frequently.

Finally, I use 4 to automatically maintain dispatches that need to be updated frequently. Examples would be TNP's WADP (updating regional officials), and daily endotarting census.

Thanks again for making this!

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

Postby HMS Unicorn » Fri Aug 19, 2016 2:48 pm

HMS Unicorn wrote:Bug report

I came across this nation: the_will_of_christ. Even though the nation is present in region Europeia, it is not listed in the following API call:

http://www.nationstates.net/cgi-bin/api.cgi?region=europeia&q=nations

It is also not mentioned in either the region or nation dumps.

On the other hand, it does seem to be present in the nation API, e.g.,

http://www.nationstates.net/cgi-bin/api.cgi?nation=the_will_of_christ&q=region

The nation moved from The West Pacific to Europeia during the major update of July 20th. It moved into Europeia after it had finished updating, and it moved out of The West Pacific while it was updating. I do not know whether the nation itself had updated in TWP by the time it moved.

The fact that it seemingly missed an update may be the cause of the bug, though it has been quite a while since then.

Regarding this bug report, the nation in question has now CTEed, so the issue is no longer pertinent.

I don't know whether the bug was fixed by admins before the nation died. I thought it'd be worth posting a reminder about this, in case the admins still intend to look into this.

User avatar
Atagait Denral
Secretary
 
Posts: 40
Founded: Jun 02, 2015
Ex-Nation

Postby Atagait Denral » Fri Aug 19, 2016 2:59 pm

similar to unread TGs, having a shard for unanswered issues would be helpful
And the private shard would also be helpful for altering nation cosmetics such as flags, mottos, etc
Having the ability to manage your entire puppet fleet with one script would be incredibly handy.

Edit:
Just started to play around with it,
Being able to retrieve your unread TGs.
Last edited by Atagait Denral on Fri Aug 19, 2016 8:58 pm, edited 2 times in total.
Vleerian Vytherov
Script Writer

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

Postby Eluvatar » Fri Aug 19, 2016 8:53 pm

HMS Unicorn wrote:3) Creating new telegram templates or API templates for that nation (obviously *not* sending them, unless it is through the telegram API).

That is, at least currently, against the rules, within or without the API.

The reason, basically, is to make sure scripters can't make individualized messages the way manual message-senders can (i.e. remarks about the nation's motto or the like). It is not legal to create templates without user action. I realize that the use-case you have in mind is for clerical changes to telegrams that would still be sent to many nations without 'customization', but the technical rule has been written to have a clear, technical, line.
To Serve and Protect: UDL

Eluvatar - Taijitu member

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

Postby HMS Unicorn » Fri Aug 19, 2016 11:50 pm

Eluvatar wrote:That is, at least currently, against the rules, within or without the API.

The reason, basically, is to make sure scripters can't make individualized messages the way manual message-senders can (i.e. remarks about the nation's motto or the like). It is not legal to create templates without user action. I realize that the use-case you have in mind is for clerical changes to telegrams that would still be sent to many nations without 'customization', but the technical rule has been written to have a clear, technical, line.

Makes sense. Given what the reasoning for the illegality is, I imagine that this is unlikely to change with expansions to the private API.

In any event, I hope applications 1-2 and 4 from my post, which are completely independent from this one, will be considered.

User avatar
Maplou
Lobbyist
 
Posts: 13
Founded: May 16, 2016
Ex-Nation

Postby Maplou » Mon Aug 22, 2016 5:00 am

Is there anyone who has an example of private shards with curl for php or any other method to get it over the web?
Just an average 7 mil ppl nation

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

Postby HMS Unicorn » Mon Aug 22, 2016 6:19 am

Maplou wrote:Is there anyone who has an example of private shards with curl for php or any other method to get it over the web?

The API shows an example, which needs to be modified a little bit for a legal API call. If you want to get the unread data, here is how you should edit it1:
Code: Select all
curl -A "YOUR_USER_AGENT" -H "Password: YOUR_PASSWORD" "https://www.nationstates.net/cgi-bin/api.cgi?nation=YOUR_NATION&q=unread"
Note that https is necessary, simply http won't work. You can replace "Password" with the autologin code or pin if that's what you want to use.

If you want to see the headers containing the pin or autologin code, you should use this:
Code: Select all
curl -A "YOUR_USER_AGENT" -H "Password: YOUR_PASSWORD" -I "https://www.nationstates.net/cgi-bin/api.cgi?nation=YOUR_NATION&q=unread"
Then in the response, search for the line "X-pin" or "X-autologin" as appropriate.

Finally, if you want to see both the headers and the actual unread data, you should use this:
Code: Select all
curl -A "YOUR_USER_AGENT" -H "Password: YOUR_PASSWORD" -D - "https://www.nationstates.net/cgi-bin/api.cgi?nation=YOUR_NATION&q=unread"
Note the dash, -, after -D, it is not a typo.

1It is possible to include the user-agent as part of the request headers passed with -H, but I prefer to set it separately using the -A flag.
Last edited by HMS Unicorn on Mon Aug 22, 2016 6:31 am, edited 3 times in total.

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

Postby HMS Unicorn » Mon Aug 22, 2016 6:22 am

[violet] wrote:I've added "Private Shards," for when you want to access information that's only available to a logged-in nation.

For now the only shard is "unread", which will tell you how many new TGs, Issues, etc, you have. But I aim to expand it in the future to cover telegrams, issues, and more. So please give this a test and let me know what you think.

For details see "Private Shards" in the API doc!

I think it would be better to edit the example curl call shown in the API, to include a user agent (see my post immediately above for code if necessary). Users may be inclined to copy/paste it as it is now, resulting in curl calls without a user agent, and therefore unwittingly breaking the API terms of use.

Sorry for the double post, but I didn't want this to be lost among the instructions in my previous post.
Last edited by HMS Unicorn on Mon Aug 22, 2016 6:31 am, edited 2 times in total.

User avatar
Maplou
Lobbyist
 
Posts: 13
Founded: May 16, 2016
Ex-Nation

Postby Maplou » Mon Aug 22, 2016 1:08 pm

HMS Unicorn wrote:
Maplou wrote:Is there anyone who has an example of private shards with curl for php or any other method to get it over the web?

The API shows an example, which needs to be modified a little bit for a legal API call. If you want to get the unread data, here is how you should edit it1:
Code: Select all
curl -A "YOUR_USER_AGENT" -H "Password: YOUR_PASSWORD" "https://www.nationstates.net/cgi-bin/api.cgi?nation=YOUR_NATION&q=unread"
Note that https is necessary, simply http won't work. You can replace "Password" with the autologin code or pin if that's what you want to use.

If you want to see the headers containing the pin or autologin code, you should use this:
Code: Select all
curl -A "YOUR_USER_AGENT" -H "Password: YOUR_PASSWORD" -I "https://www.nationstates.net/cgi-bin/api.cgi?nation=YOUR_NATION&q=unread"
Then in the response, search for the line "X-pin" or "X-autologin" as appropriate.

Finally, if you want to see both the headers and the actual unread data, you should use this:
Code: Select all
curl -A "YOUR_USER_AGENT" -H "Password: YOUR_PASSWORD" -D - "https://www.nationstates.net/cgi-bin/api.cgi?nation=YOUR_NATION&q=unread"
Note the dash, -, after -D, it is not a typo.

1It is possible to include the user-agent as part of the request headers passed with -H, but I prefer to set it separately using the -A flag.

I was looking for some way to I guess, use it on the web. For Example in javascript, php or html
Just an average 7 mil ppl nation

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

Postby [violet] » Mon Aug 22, 2016 5:38 pm

HMS Unicorn wrote:I think it would be better to edit the example curl call shown in the API, to include a user agent

Yes, indeed! Done, thanks.

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

Postby [violet] » Mon Aug 22, 2016 5:38 pm

Added a new private Nation shard: "notices."

User avatar
Scilla
Civilian
 
Posts: 1
Founded: Jan 27, 2016
Ex-Nation

Postby Scilla » Mon Aug 22, 2016 6:34 pm

So I am making a discord chatbot using discord.js and I want to have a command where you type !nationname: (and then the name of the nation), and it would reply with a link to the nation you just named. One of my regionmates did the same, only in another language. How would I do this? Do I need NS Api?

User avatar
Flanderlion
Minister
 
Posts: 2228
Founded: Nov 25, 2013
Psychotic Dictatorship

Postby Flanderlion » Mon Aug 22, 2016 7:44 pm

Scilla wrote:So I am making a discord chatbot using discord.js and I want to have a command where you type !nationname: (and then the name of the nation), and it would reply with a link to the nation you just named. One of my regionmates did the same, only in another language. How would I do this? Do I need NS Api?

Wrong thread, probably better to split it out. But what you need to do is receive a string from the user (whatever they type, e.g. Flanderlion) and turn it into http://www.nationstates.net/nation=flanderlion. It doesn't need an API, or in fact need to interact at all with the NS site, only if the bot is pulling data from the site like population, influence, endorsements etc.

So in pseudo code:
User input = String Nation_Input
URL = http://www.nationstates.net/nation=
Output = (URL + Nation_Input);
Print Output;

On topic though - is there any way to get just the new notifications rather than the last X notifications with the new shard?
As always, I'm representing myself.
Information
Wishlist

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

Postby [violet] » Mon Aug 22, 2016 8:36 pm

Flanderlion wrote:On topic though - is there any way to get just the new notifications rather than the last X notifications with the new shard?

By default it works the same way as the regular site, where it returns new notifications plus any from the last 48 hours. The new ones have a tag like: <NEW>1</NEW>. I could add a "newonly" parameter or something.

PreviousNext

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: No registered users

Advertisement

Remove ads