This is a how-to article for sending messages to players through the Politics and War API.
The API endpoint to send messages through is: at https://politicsandwar.com/api/send-message/
This API endpoint accepts a POST request with the following parameters:
key : This is your API key, found on the account page.
to : This is the Nation ID of the recipient. Note that this is not the leader name like in normal messaging.
subject : This is the subject of the message. This cannot be null, and can be up to 50 characters in length.
message : This is the body of the message. You can use HTML to format your message.
An example of a successful response from the server looks like:
{
"success": true,
"recipient": "196880",
"subject": "test"
}
Here are a list of errors you may experience and why you may receive them.
If you do not include a valid API key with your request, you will see the message:
{
"success": false,
"general_message": "Invalid API key."
}
If you try to send a message to yourself, you will see the message:
{
"success": false,
"general_message": ["You cannot send a message to yourself."]
}
You must identify a primary recipient by their nation ID. If that ID does not exist, you will see the following message:
{
"success": false,
"general_message": ["The recipient does not exist. Using this API endpoint, you must send messages to players by their Nation ID rather than their leader name."]
}
If you do not include the subject field, you will see the following message:
{
"success": false,
"general_message": ["You must include a subject in your message."]
}
If you do not include the message field, you will see the following message:
{
"success": false,
"general_message": ["You did not include a message body."]
}