Can we use Reflow product data to search product in Search bar of website

It is working, what if products are more than 99

I made an experiment and it worked but I do not know how to write proper code for it.

I added products?page=2 at the end so it brought search results for older products, however, it stopped fetching for newer products then. Please see here:

let products = await fetch(
    "https://api.reflowhq.com/v1/stores/1736447397/products?page=2"
  ).then((r) => r.json());

If we can make a combination of URLS for fetch to take data from page=1 and page=2 and so on, we can then use that combined data to search…

Then put perpage=999999999999
:")

Yep it should be perpage, all lowercase. We fixed it in the documentation. Nice detective work :wink:

2 Likes

100 is the max the API returns right now. When the official search component arrives this shouldn’t be a problem any more.

1 Like

EDIT: This might not work until you have 100+ products…


Try replacing the begining of the script to this:

async function search(ss) {
  let resultcount = 0;
  let searchstring = ss;
  let products = await fetch(
    "https://api.reflowhq.com/v1/stores/1736447397/products/?perpage=100"
  ).then((r) => r.json());
    
    
    let products2 = await fetch(
    "https://api.reflowhq.com/v1/stores/1736447397/products/?page=2&perpage=100"
  ).then((r) => r.json());
    
 productsmerged = products.data.concat(products2.data);

     
   productsmerged.forEach(function (product) {
    const cts = JSON.stringify(product).toLowerCase();
; //cts convert to string

It works in theory, looks like you have 40 products at the moment, we will see when you’ve added another 60 :slight_smile:

Hi Richards,

When I use the attached code, I get the following error
searchjserror

This is the code segment the error refers to:

if (searchphrase.length < 2) {
document
.getElementById(“searchResults”)
.append(“Please enter a longer search phrase”);
} else {
search(searchphrase);
}

I’ve tried messing around with ID, and the like but can’t get the search to work. Any idea what’s wrong?

This is now out of date, as the official reflow search has been released.

just add the product search from the component/studio tab
image

but from what i see there is no way to add a link to go directly to that product so your code is better!

EDIT - found a way thanks

All the instructions are here: