Fetch API and store it in a collection

So im working on a project in which im fetching an API directly with wixcode and visualizing it with repeaters. (doing it by hand)

But meanwhile i progress, i realize i need hundreds of pages (with the same layout) and i will have to do it by hand all the hard work. But, if i fetch the API and store it right away in a collection, so i can create a dynamic page, it will be great.

Any piece of advice on the procedure to do that?

PS: is there a way i can create MY OWN REPEATERS?

Thanks in advance

Hi

It is pretty straight-forward if you already have successfully fetched. You just need to map the values you’re interested into an object and save it to the correct collection.

Example below.

let res = null;
	// FETCHING
  try {
		res = await fetch (wixRestaurantAPIUrl + "organizations/666666666677777/orders?viewMode=restaurant",{ "method": "GET",	"headers": { "Authorization": "Bearer " + accessToken}});
	}
	catch(error)
	{
			await log("", "", error.message, "ERROR");
			return;
	}
  
  // MAPPING VALUES TO OBJECT
  let commande = {
		"orderId":jsonWix["value"]["results"][0]["id"],
		"clientName":jsonWix["value"]["results"][0]["contact"]["firstName"] + " " + jsonWix["value"]["results"][0]["contact"]["lastName"],
		"clientPhone":jsonWix["value"]["results"][0]["contact"]["phone"]
	};
  // INSERTING
  wixData.insert("Commandes", commande)
	.then( (results) => {
		log(commande["orderId"], "", "Commande créée", "INFO");
		return;
	} );

I did successfuly fetched de API into a grid. Since im not a developer, im getting a hard work trying to figure out how to implement the code above, can you give me some clues ?

For instance:

I run the code on the backend?
Where do i put the parameters im working with from the API?
In the insert part, “Commandes” is the BS im putting the info right?

Here is the API from the frontend that is connected to the grid:

$w.onReady(function  () {
	getUsatech()
		.then(newsData => {
			//ADD ID DYNAMIC
			for (var i = 0; i < newsData.articles.length; i++) {
				newsData.articles[i]["_id"] = "news" + i;
			}
                        //all the parameters into the grid from the API
			$w("#repUsatech").onItemReady(($w, itemData, index) => {
				$w('#imgUsatech').link = itemData.url;
				$w('#imgUsatech').src = itemData.urlToImage;
				$w("#newsBody").text = itemData.description;
				$w('#titUsatech').text = itemData.title;
				$w('#authorUsatech').text = itemData.author;

			});

			$w("#repUsatech").data = newsData.articles;
		});
	});

Thanks in advance!!

hi any one help me to intregrate indica online product apis to wix website