The term API stands for Application Programming Interface, which you’ve probably never heard of. The best way to think of it is like this. There’s the GUI (Graphical User Interface), you’ve probably heard of that, and the API. The GUI is some nice text and images and is designed for users (you) to interact with. The API on the other hand, is essentially text and some internet communication that is designed for computers to interact with and receive data in the most efficient format possible.
The P&W API is composed of a patchwork of versions and webpages developed over the course of the entire game. For historical purposes I’ll mention that v1 and v2 exist, however v3 should be used for all new projects going forward. v3 provides a much better interface as well as massive amounts of additional data and functionality.
If you’re interested in learning more about the API, head on over to the P&W Discord server and use the ;role api command to get access to the API channel to ask any questions!
So now that you know what an API is, you’re probably asking yourself “Why should I care?” It’s a good question, why should you? Well, if you’ve ever interacted with the community on Discord you’ll find lots of wonderful Discord bots and various spreadsheets to help with the game, all of that is powered through the API. The API makes it really easy to, say, get the amount of soldiers on every nation in an alliance, or the amount of cities each member has. You could spend an hour clicking through the member list and recording the data, or you perform a simple query in a programming language and run with it that way!
The API is best served as a tool to make your life, and the lives of everyone else, much easier. It makes it really easy to get important information without having to leave Discord, and to get information in ways that the game simply doesn’t provide. Not only that, but use of the other programming features in conjunction with the API allows really awesome things to arise, like banking systems for alliances!
NOTE: Use of the API to fully automate gameplay is NOT ALLOWED and WILL result in punishment from the moderation team. Actions to interact with the game should be confirmed or initiated by a user, NOT done automatically on a loop or in response to a change in the game.
If you want to play around with how to shape your requests, you can use the playground:
https://api.politicsandwar.com/graphql-playground
It’s important that you append ?api_key=xxxxxx to the request url (towards the top of the page, but not the page url itself). If you fail to do this, you will be met with errors about the client being unable to reach the server and/or errors about the api key being entered incorrectly. Please note that you have to use your own API key, instead of xxxxxx. Your API key can be found on the bottom of your account page: https://politicsandwar.com/account/
In order to see type details and arguments, you can press the “docs”-button on the right-hand side of the playground.