skip to Main Content

I’m trying to implement the predictive search API to create a custom solution when a product is out of stock. The idea is that we want to show an alternate product OF OUR CHOOSING (i.e. not using the automated recommendations). We have added a tag to all products with an alternate SKU that we want to show if an item is OOS. The Predictive Search API seems the perfect solution for this, but I can’t get it to give me any results.

I found this forum post that seems to answer this exactly, but it doesn’t work for me.

Here is the URL structure I’m trying to use:

https://example.com/search/suggest.json?q=searchstring&resources[type]=product&options[fields]=title

When I send this, either from Postman or from a page on the site, I get this:

{
    "resources": {
        "results": {
            "products": []
        }
    }
}

HOWEVER

If I alter the URL slightly to request the predictive search HTML snippet (as is done in the theme), it returns results:

https://example.com/search?view=ajax&q=searchstring&options[prefix]=none&type=product

Does anyone know what’s wrong here? Why is the HTML version of the API working but the JSON version isn’t? Am I doing something wrong? Is there a setting somewhere I missed?

2

Answers


  1. Chosen as BEST ANSWER

    I don't understand this, but it seems that the resources[options][fields] parameter is not only required, certain fields are required as well. In my case, I had to request the variants.sku field in order to get anything. Furthermore, that parameter is supposed to limit what you get, but it doesn't limit anything at all, I get everything.

    Here are 2 sample URLs. The first one doesn't work, the second one does. Does anyone have any idea why???

    https://example.com/search/suggest.json?q=searchstring&resources[type]=product&resources[options][fields]=title

    VS

    https://example.com/search/suggest.json?q=searchstring&resources[type]=product&resources[options][fields]=title,variants.sku


  2. I think you need to check and mode the query string parameters to correct format and then it works well into JSON format also.
    There are some issues with the format and need to update it like

    https://example.com/search/suggest.json?q=searchstring&resources[type]=product&resources[options][fields]=title

    You can check more about this Here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search