P&Wpedia

Alliance | API | City | FAQ | Misc | Nation | Resource | War


A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z



How to Send Messages through the API

This is a how-to article for sending messages to players through the Politics and War API.

Overview

The API endpoint to send messages through is: at https://politicsandwar.com/api/send-message/

Parameters

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.

Response

An example of a successful response from the server looks like:

{

   "success": true,

   "recipient": "196880",

   "subject": "test"

}

Errors

Here are a list of errors you may experience and why you may receive them.

Invalid API Key

If you do not include a valid API key with your request, you will see the message:

{

   "success": false,

   "general_message": "Invalid API key."

}

Self Message

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."]

}

Recipient Does Not Exist

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."]

}

No Subject

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."]

}

No Message Body

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."]

}


Category: API