What’s the best way to call information back for a list of items from the API?
For example, say I need the info back for just 4 items for use in a recently viewed script on the home page. I don’t want all items back as the catalogue could be large, and I don’t want to make 4 calls.
What I’d like to do is:
https://api.reflowhq.com/v2/stores//products/,,
on your product page
Your product page has a search param when a user visit the product page
get the search param product
check if the product exist in localStorage recentlyViewed if not
fetch the product from the reflow api
https://api.reflowhq.com/v2/stores/YOUR-STORE-ID/products/${product}
if the lenght of the recentlyViewed array > 3 removed the oldest product
push the product to the recentlyViewed array and store it in localStorage
on your home page
get the recentlyViewed from localStorage
for each product in the recentlyViewed array show on your recently-viewed section on your home page
if you want more persist data use indexedDB instead of localStorage. Then even when a user clear the browser your recently viewed data will persist
I hadn’t considered the localStorage option, thanks
I have a working ‘recently viewed’ script with cookies, but now I also need stock checking, I’m also doing something similar for an ‘add to favourites’ page, so hence the need to query the API with as few calls as possible.
Thank you for the feedback! After reading what you’re trying to achieve, we realized that our API doesn’t accommodate this use case very well so we added an ids
parameter to the get products endpoint. You can pass a list of ids and it will return only the products that match.
That’s great thanks.
Is there a reason why the V2 toolkit js file points to V1 of the API? I only ask as I’d also like to access the SKU, but this is only in V2
The toolkit and api have independent versioning. We haven’t migrated the toolkit to the new api in order to maintain compatibility with people’s integrations. A future v3 of the toolkit will use the latest api. It’s not a problem to use multiple versions of the api in your project.