I’m trying to display stock levels or out of stock on my website built with next.js and sanity. I know i need to fetch from the api but need an example or some guidance and the docs are not very detailed here. Can anyone point me towards an example project or offer some guidance.
You can see the remnants of my attempts below.
export async function getStaticProps({ preview = false }) {
const allproducts = await getAllAttachmentsForHome(preview)
const relevantMakes = await getRelevantAttachmentMakes(preview)
const res = await fetch(https://app.snipcart.com/api/products
, {
headers: {
‘Authorization’: 'Basic ’ + Buffer.from(API_KEY + ‘:’).toString(‘base64’),
‘Accept’ : ‘application/json’,
}
})
const data = await res.json()
return {
props: { allproducts, relevantMakes, data, preview},
revalidate: 1
}
}
Repo to the project here:
https://github.com/chrisbell2520/gem-models
And live site