Howto get data via REST-API into your vault?

What I’m trying to do

Hi,

i’d like to do a simple GET-request towards a REST-API and render the result within my vault as a table or list.

Things I have tried

I have written a small js-script, that is supposed to be called by the DataView-plugin. Unfortunately, no data is rendered in my vault. I can run the script using vscode and nodejs and also debug it. While debugging i can see that the expected data is there. I just don’t understand the DataView-interface and how to use it properly. Here is the script. It’s supposed to get shopping list items from my grocery instance.

// const https = require('https');
const apiKey = "redacted";
const getOptions = {
	host: "mydomain.com",
	path: "/api/objects/shopping_lists",
	headers: {
	"GROCY-API-KEY": apiKey,
	},
};
async function getShoppingLists() {
	return new Promise((resolve, reject) => {
		let shoppingLists;
		https.get(getOptions, response => {
			response.on('data', chunk => {
				data.push(chunk);
			});
			let data = [];
			response.on('end', () => {
				shoppingLists = JSON.parse(Buffer.concat(data).toString());
				resolve(shoppingLists);
			});
		})
		.on('error', err => {
			console.log('Error:', err.message);
			reject(err.message);
		});
	});
}

async function getListItems(listId){
	return new Promise((resolve, reject) => {
		getOptions.path = "/api/objects/shopping_list";
		https.get(getOptions, response => {
			response.on('data', chunk => {
				data.push(chunk);
			});
			let data = [];
			response.on('end', () => {
				items = JSON.parse(Buffer.concat(data).toString());
				let filteredItems = items.filter((i) => i['shopping_list_id'] == listId);
				resolve(filteredItems);
			});
		})
		.on('error', err => {
			console.log('Error:', err.message);
			reject(err.message);
		});
	});
};

console.log("I'm here");
getShoppingLists()
	.then(shoppingLists => {
		let shoppingList = shoppingLists !== undefined && shoppingLists.find((list) => list['name'] == "Einkaufszettel")
		if (shoppingList !== undefined ){
			getListItems(shoppingList['id'])
				.then(items => {
				  console.log("I'm here");
dv.table(["ID", "Menge"], items.map(i => [i.id, i.amount]));
				})
				.catch((reason) => {
					console.log(reason);
				});
		}
	});

This is how i embed the script in my vault:

await dv.view("Skripte/grocy_shopping_list");

Do i have to pass the dv-interface as a parameter or is it automatically made available within my script?
Is it correct to do the rendering within the script, or can i pass the data back to the vault and do the rendering there with dataview?

Currently i don’t see anything when " executing" the script in the vault.

Any hints appreciated.

Edit: I have commented out the first line, as dataview was complaining, that require is not available.

Without it your https is void and you’ll never get your script to do its work… you need to figure that out, before there is any point addressing any other issues.