Sending mail into Sway Charts Pro from outside the platform

It's possible to send mail into Sway Charts Pro from outside the platform, from any environment which can make HTTP requests. If you are sending to a mobile device this also generates an iOS/Android push notification, and so you can receive alerts on your phone (or tablet) from external sources.

For example, you can send messages into Sway Charts Pro from a huge range of sources, covering everything from a financial model in Microsoft Excel to an EA in the MT4 or MT5 trading platforms.

The examples in this guide use the general-purpose command-line tool curl. This is just a way of demonstrating that mail can be sent into Sway Charts Pro from anything which can make HTTP requests. You can use the help material for curl to translate from these examples to any other environment which can make HTTP requests.

All mail in Sway Charts Pro is sent to devices (not to people, or to trading accounts). You need three pieces of information in order to send mail into Sway Charts Pro:

· The mail ID of your device, which will be an 8-character code such as DMZLXCVG. You can see this by opening the new-mail window in Sway Charts Pro, from the Mailbox widget.

· Your sender password, which is a long alphanumeric string. You can see this by doing a long tap/click over your ID in the new-mail window. This expands the new-mail window to show extra information.

· Your message server. This is also shown when you do the long-tap/click over the ID.

You send mail by making a POST request to the messaging server, with the request body being a block of JSON describing the message. For example, using curl:

curl --url "https://proapimessaging.swaycharts.io/send?DMZLXCVG" --request "POST" --data-raw "{'password':'C9753B5FA8E5417BA064618AF65E2520', 'subject':'Test message'}"

To confirm, what this example is doing is making a POST request to a URL which consists of three parts:

· The message server, such as https://proapimessaging.swaycharts.io

· The path /send

· Your device ID as the request's querystring: ?DMZLXCVG

The body of the POST is then a block of JSON data. As a minimum, it must contain your sender password and a subject line for the message.

The values which you can include in the JSON body, describing the message, are as follows. The password and subject are compulsory. Everything else is optional.

Property

Description

password

The sending password for your device, as described above

subject

A subject line for the message (max 200 characters)

body

An optional body for the message (max 4KB)

to

Recipient ID, if sending a message to another device. If there is no to value, then the message is simply sent to your own device as identified by the request querystring.

priority

Priority for the message

attachment

Attachment data

noPush

Turns off any iOS/Android push notification

You can send mail to other people's devices as well as your own, by setting the to property. But it's deliberate that there is no way of discovering someone else's ID without them looking it up – in the Sway Charts Pro new-mail window as described above – and telling it to you.

Messages to your own device can have priority. This is ignored if you use the to value to send a message to another device. Priorities are as follows:

Priority

Description

0

Normal priority

1

Message is marked in red in the Sway Charts Pro mailbox

2

Sway Charts Pro displays a red new-mail icon in its banner until the message has been read

3

Message is forced to open in the platform (after next log-in, if Sway Charts Pro is not currently running)

The optional message body can be any of three things:

· Plain text

· HTML – a full HTML document with <html> and </html>

· The URL of a web page. This must be an https:// page, not http://, and the page must not set the X-Frame-Options header.

For example, the following sends a priority 2 message with the www.swaycharts.io website as the content:

curl --url "https://proapimessaging.swaycharts.io/send?DMZLXCVG" --request "POST" --data-raw "{'password':'C9753B5FA8E5417BA064618AF65E2520', 'subject':'Test message', 'body':'https://www.fxblue.com', 'priority': 2}"

If you are sending to a mobile phone (or tablet), then Sway Charts Pro mail generates iOS/Android push notifications by default. You can turn this off by setting 'noPush':true in the JSON (or any value for noPush – it is not actually treated as a boolean).

Mail into Sway Charts Pro is subject to a quota – for example, a maximum of 60 requests per hour. Messages will be rejected if you try to send too many (including invalid requests such as those missing a subject line, or with a non-existent recipient).

The HTTP status code of the response from the server will be 200 if the message succeeds. If the message fails for any reason, then the status code will be 400. The body of the response from the server is JSON consisting of either one or two values:

Property

Description

success

True/false, indicating whether the message succeeded (duplicating the 200/400 status code of the response)

error

If success=false, a description of why the message failed

Like with messages sent from inside the Sway Charts Pro platform in its new-mail window, you can also add attachment data. This works as follows:

· You use the Data Transfer widget in Sway Charts Pro to download an attachment (a .Sway Charts Protransfer file)

· You open the .Sway Charts Protransfer file in any text editor

· You add the attachment data (beginning AAAA…) into the message

Last updated