Apologies for my slight newbieness...
I need a javascript (or php) script that will automatically check a JSON file (via HasOffers API call) for changes and then execute a php script (which I already have -- it utilizes OneSignal to send a push notification to my phone) once changes are detected.
So here's my code for calling the API in javascript:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.hasoffers.com/Apiv3/json?NetworkId=SomeNetwork&Target=Affiliate_Report&Method=getStats&api_key=2c0ce8e72df0802c900d1fb6bd34e&fields%5B%5D=Stat.conversions&filters%5BStat.date%5D%5Bconditional%5D=EQUAL_TO&filters%5BStat.date%5D%5Bvalues%5D=2016-01-25', true);
console.log(xhr);
// Response handlers.
xhr.onload = function () {
var repos = JSON.parse(xhr.response), i, reposHTML = "";
for (i = 0; i < repos.response.data.data.length; i++) {
reposHTML += repos.response.data.data[i].Stat.conversions;
}
document.getElementById("fetch").innerHTML = reposHTML;
};
xhr.onerror = function () {
alert('error making the request.');
};
xhr.send();
How can I integrate a javascript code into this which "listens" for changes in the API/JSON file (specifically a numerical value inside response.data.data[0].Stat.conversions within JSON file), and then executes another php file that I have when the number goes up by one increment?
So if within the JSON file the Stat.conversions = 30, and then it goes to 31, I want the javascript to automatically execute my php script.
I hope that is clear enough. Please let me know if I need to clarify anything else.
Thanks!!