I have very little knowledge of REST API and Javascript. However, I now need to work on a REST API of a third party company which is sending emails for my company and to get the report data through the REST API.
The data can get through a GET method with an URL with TOKEN: https://www.probancemail.com/rest/stats/?&token={platformtoken}
Sample of JSON array as below:
{
"bounce":2,
"campaign_external_id":"RT1-",
"campaign_name":"RT1-Welcome1",
"click":19,
"delivered":333,
"open":69,
"sending_external_id":"RT-PWDE1-20170617",
"sendingtime_ts":1497650423000,
"sent":335,
"spam":0,
"template_external_id":"0193",
"unsub":6
}
What I need as a first step is to retrieve the JSON data from the third-party based on the URL with token, and parse the JSON data through Jquery and display it on the webpage as table(HTML). To achieve that, I have found the Jquery codes below:
<!DOCTYPE html>
<html>
<head>
<script>
var url = 'https://www.probancemail.com/rest/stats/?&token={platformtoken}'
$(document).ready(function () {
$.getJSON(url,
function (json) {
var tr=[];
for (var i = 0; i < json.length; i++) {
tr.push('<tr>');
tr.push("<td>" + json[i].campaign_name + "</td>");
tr.push("<td>" + json[i].campaign_external_id + "</td>");
tr.push("<td>" + json[i].sending_external_id + "</td>");
tr.push("<td>" + json[i].sent + "</td>");
tr.push("<td>" + json[i].delivered + "</td>");
tr.push("<td>" + json[i].open + "</td>");
tr.push("<td>" + json[i].click + "</td>");
tr.push("<td>" + json[i].spam + "</td>");
tr.push("<td>" + json[i].unsub + "</td>");
tr.push('</tr>');
}
$('table').append($(tr.join('')));
});
</script>
</head>
<body>
<table></table>
</body>
</html>
However, this code doesn't work, I think it is because of the token, the GetJSON function doesn't get the JSON. However, I'm very new to this, so I don't have any insights.
Will you please take a look and help me figure out the problem? Any advice is welcomed! >> Maybe I shouldn't use Jquery even?
Thanks in advance!