I’m unsure how to parse a JSON response from an API call into repeater elements on my page.
I’ve been looking through the forum and tutorials but cant get my head around it as I’m not great at programming. The JSON response is below:
{...}
products: {...}
filters: {...}
sortOptions: {...}
a_z: "A to Z"
last_updated: "Last Updated"
featured: "Featured"
top_rated:"Top Rated"
most_popular:"Most Popular"
most_commented:"Most Commented"
pagination: {...}
BackEnd code
const headers = {'Content-Type':'application/json','x-api-key':'**************************'}
const url = 'https://www.bimstore .co/api/v2/system/products?category_uuid=ca46a938-1d8e-414c-ba0d-9696138a9fe6';
export function getProducts() {
return fetch(url, {method:'GET', /*body: JSON,*/headers})
.then(response => response.json())
}
console.log("Url: " + url)
Front end code (which is mostly comments at the moment)
import { getProducts } from 'backend/Backendcall'
$w.onReady(function () {
getProducts().then((response) => console.log(response).then($w('#repeater1').data = response.items));
//$w('#repeater1').data = response.
//$w('#dropdown1').options[{response.sortOptions}];
})
so my queries are:
- I’ve been told the response has a parent/child relationship, can someone explain this to me in lay person terms?
- How can I populate a drop down with the “sortOptions” response data?
- Can someone explain how to parse all of the response data into an array of some sort to add it to repeater items?
any help would be hugely appreciated to a novice like me!