Grab data from API json and store it in the database

Hello. I tried to follow this tutorial Ingesting and Visualizing API Data with Stitch and Charts | MongoDB Blog, but it seems to be outdated.

I cannot find any services tab

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

Hi @David_Berndtsson - welcome to the community forum.

That post is pretty old (and it dates back to before “Stitch” was renamed to “MongoDB Realm”. This blog series might be a better starting point Coronavirus Map and Live Data Tracker with MongoDB Charts

Thanks, but it doesn’t show any code, or any tutorial on how I can grab data from an API and store it in the database

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 ='http');
  var weatherApiInfo = context.values.get('weatherApiInfo');
  let url = `${}&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 ='mongodb-atlas').db('weather').collection('observations');
    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.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.