Basically I’m trying to grab a specific value from remote API json (accessable via https on the web) and store it in a database. This Json api displays data in realtime so I want to grab it every 10 minutes and store the values it grabbed to later display this as a chart to show the history of the values
The old post you referenced including some (now) Realm function code to fetch data from an API and store it in Atlas…
exports = function(payload) {
const httpService = context.services.get('http');
var weatherApiInfo = context.values.get('weatherApiInfo');
let url = `http://api.openweathermap.org/data/2.5/weather?q=${weatherApiInfo.city}&units=metric&appid=${weatherApiInfo.appId}`;
console.log("Fetching " + url);
return httpService.get( {url: url}).then(response => {
let json = JSON.parse(response.body.text());
json.observationDate = new Date(json.dt * 1000);
var collection = context.services.get('mongodb-atlas').db('weather').collection('observations');
collection.insertOne(json);
console.log('Inserted document!');
});
};
A major change since then is that you don’t have to bake your own solution to run that function periodically – you can now use Realm scheduled triggers to keep it all inside your Realm app.
You can also take a look at this repo – we’re currently using this to periodically fetch data from some APIs for an internal dashboard.