Last active
September 28, 2017 18:47
-
-
Save leadbi/d81056a6dc1474e747c350559aa67b46 to your computer and use it in GitHub Desktop.
SwiftMTA Javacript Logs API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$username = 'dwtgroup'; | |
$password = 'change_me'; | |
$expire = date("c",strtotime("+1 day")); | |
$alg = 'sha256'; | |
// generate authorization | |
$authorization = "$username;$expire;$alg"; | |
$authorization = $authorization . ";" . hash_hmac($alg, $authorization, $password); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> Client Side API </title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<h1>Hello, world!</h1> | |
<script src="http://code.jquery.com/jquery.js"></script> | |
<script> | |
$(document).ready(function () { | |
var api_authorization = "<?= $authorization ?>"; | |
var endpoint = 'https://mailertrk.com'; | |
function queryLogs(endpoint, api_authorization, query){ | |
var url = endpoint + '/api/v1/logs/query.json'; | |
var deferred = jQuery.Deferred(); | |
$.ajax({ | |
type: 'post', | |
dataType: 'json', | |
url: url, | |
contentType: 'application/json', | |
data: JSON.stringify(query), | |
headers: { | |
"x-authorization": api_authorization, | |
}, | |
processData: false | |
}).done(function(data) { | |
deferred.resolve( data ); | |
}).fail(function (err) { | |
deferred.reject( err ); | |
}); | |
return deferred.promise(); | |
} | |
queryLogs(endpoint, api_authorization, { | |
'filters': { | |
'email_from': 'test@test.com', | |
// or | |
'reference_id': 'Your header uuid' | |
}, | |
'projection': {}, | |
'order': {} | |
}).then(function (logs){ | |
console.log(logs); | |
}, function (err) { | |
console.error('Something went wrong!'); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment