Show stock levels

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

Hi @Chris,

Can you give us more detail as to what is not working as expected?

Hi Lea, just looking for some guidance on how to display stock levels on the front end website. I have tried a GET request as in my original question but i get an error in the console saying " {“message”: “An error has occured”} Returned when using application service with dynamic api controller · Issue #71 · aspnetboilerplate/aspnetboilerplate" when i try to console out the data.

I’ve seen that people have managed it but cannot find a good example to steal from :grinning:

Hi Lea, have you any advice please?