Since I've been struggling to get email to function reliably, I'm looking into alternate methods. PushBullet has an open API, but I am not seeing how to send the appropriate auth information via the API key I have squired. If I use the following from a linux command line, I get the message:
curl -k -o /dev/null -s -H "Content-Type: application/json" -u "MY_API_KEY": -d "{\"type\": \"note\", \"title\": \"This is a test\"}"
https://api.pushbullet.com/v2/pushesHere is the code I'm trying to use:
var httpRequest = new XMLHttpRequest();
var token = 'MY_API_KEY'; //This is the key I received from PushBullet
var url = "
https://api.pushbullet.com/v2/pushes"; //URL to send notes
var message = "{\"type\": \"note\", \"title\": \"This is a test\"}"; //Message to send as type Note
function OnStart()
{
httpRequest.onreadystatechange = function() { HandleReply(httpRequest); };
httpRequest.open("POST", url, true);
httpRequest.setRequestHeader( 'Content-Type', 'application/json' );
httpRequest.setRequestHeader( 'Authorization', token );
httpRequest.setRequestHeader( 'DATA', message );
httpRequest.send();
}
//Handle the servers reply (a json object).
function HandleReply( httpRequest )
{
if( httpRequest.readyState==4 )
{
//If we got a valid response.
if( httpRequest.status==200 ) console.log( "Response: " + httpRequest.responseText);
//An error occurred
else console.log( "Error: " + httpRequest.status + httpRequest.responseText);
}
}