Znote (recipes)
  Get Znote  

🌍 Integrate Online Datasets

How to integrate online Datasets with your note

 

🌍 Integrate Online Datasets

If your data comes from a URL or a private database, you can retrieve and save it locally using a dedicated code block.

Key Parameters:

  • noDeploy → Excludes the block when publishing the note.
  • hide → Hides the block from the online report.

1️⃣ Fetch and Store Dataset Locally

This example fetches data from an API and saves it as a local JSON file.

// Fetch data from API
const r = await fetch('https://www.govtrack.us/api/v2/role?current=true&role_type=senator');
const json = await r.json();

// Alternative: Retrieve data from an SQL database
// const json = await sqlDatabase("SELECT ...");

// Write data to a local file
_fs.writeFileSync(__dirname + "/senators-dataset.json", JSON.stringify(json));
print("✅ Dataset saved locally as 'senators-dataset.json'");

2️⃣ Use the Local File in Your Published Note

The files parameter ensures that the dataset file is included when publishing.

// Load the dataset from the local file
const senators = require("./senators-dataset.json");

// Display data in a table
showDatagrid({
  data: senators.objects.map(e => e.person),
  pagination: true
});

Related recipes