Product Search By Title Using API

Pulkit_Saxena
Shopify Partner
1 0 0

Hi,

I am looking for searching products based on title.

But I can't  find any search API for products in API section. Have I missed it somewhere or any info regarding this is appreciated.

Thanks !

0 Likes
Thuong_Mai
Shopify Partner
42 0 0

Hi Pulkit,

You should use the /admin/products.json API, fields=id,title, limit=250 and since_id query parameters to fetch all products, and then perform searching on your side. That's the way I've been using so far.

A Shopify agency that helps build, promote, and expand e-commerce businesses.
0 Likes
dawich77
Shopify Partner
7 0 1

It's a little bit of work to set up, but I used the python api and created a sqlite database that stored all of the product id's and associated sku's so that I could just query the database and look up the product directly by id, given a specific sku:

product = shopify.Product.find(id)

Then I can make changes to the product and save it. You could potentially do the same thing with titles instead of skus.

0 Likes
Jared_Burns1
Shopify Partner
30 0 7

You can search by title using the "title" param on the /admin/products.json API that Shopinet mentioned. As in:

/admin/products.json?title=<searchString>,limit=250,page=1,fields="id,title,etc"

I've found that some very simple matching is done. For example, searching with a title of "blue" will match a product named "blue shirt". But I haven't found a way to insert real wildcards... and the matching from the API isn't as good as the matching demonstrated by Shopify's own admin UI widgets.

So for now I'm using the "title" query param, but planning to pull everything into my own searchable datastore in the near future.

Mounir_HAB-ARRI
Shopify Partner
11 0 12

Hi Burns,

I did an Ajax request inside my Shopify App using this "/admin/products.json?title=<searchString>,limit=250,page=1,fields="id,title,etc" to search product by title ... but i get nailed by CORS.

Is there any way to use Ajax API call inside Shopify App or any alternative solution to Filter/Search data from API ?

Thank you,

0 Likes
Jared_Burns1
Shopify Partner
30 0 7

I don't believe the CORS issue you're seeing is related to the query params used for searching products by title. This sounds like a general issue getting started with the API.

For what it's worth, you need to call the JSON API from your registered application... by which I mean your registered, authenticated server needs to make the call to the Shopify server. Not the browser. (I mention this because you said you're trying to use Ajax.)

0 Likes
Mounir_HAB-ARRI
Shopify Partner
11 0 12

Thank you Jerard,

Actually I have an Embeded App on Shopify and its run on my private VPS with an SSL certificate ... and I make calls to the Shopify API by a library called ShopifySharp ... every thing work great, But I need to filter & search products by Title! 

Is there any alternative way to do a client side filter & search ? I heard about the App Proxy but i'm not sure !

Thank you.

0 Likes
Akki
Shopify Partner
16 0 4

Hi Jared,

Did you find any way to search with wildcards in API. Currently, the api is not searching for picking the case sensitive words e.g "/admin/products.json?title=Test is not giving me the "test" results.

Thank you,

Ankit

carchrae
New Member
1 0 0

 

perhaps the api changed, but i wanted to note this is not correct

 

 

/admin/products.json?title=<searchString>,limit=250,page=1,fields="id,title,etc"

 

 

rather, you want the extra options added with `&` and not " so instead

 

/admin/api/2020-04/products.json?title=<searchString>&limit=250&fields=id,title

 

also page=1 isn't supported anymore, see here for updated pagination docs https://shopify.dev/tutorials/make-paginated-requests-to-rest-admin-api

 

 

0 Likes
albabameem
New Member
2 0 0

For all those still wondering how to fix this. 

  1. Title parameter in the API cannot be used to search products, it will only work if you pass the exact product name. 
  2. For CORS, hit the API on the backend rather than the client side.
  3. This is not the optimum solution but the best way I could make it work so far is by looping through all the products using since_id and then filtering the results out. Here's my code

 

        $keyword = $request->keyword;
        $active = true;
        $productsArray = [];
        $sinceId = 0;

        //loop until 0 products are returned
        while($active){
                $products = hitCurl('/admin/api/2021-01/products.json?limit=250&since_id=' . $sinceId, 'GET', $curlFields = "");
            if(sizeof($products['products']) <= 0){
                //break the loop when result is empty
                $active = false;
            }

            //loop within the results and push the product to an array
            for ($i = 0; $i <= sizeof($products['products']) - 1; $i++) {
                array_push($productsArray, $products['products'][$i]);

                //update the since_id to the latest id in the response
                if($i == sizeof($products['products']) - 1){
                    $sinceId = $products['products'][$i]['id'];
                }
            }
        }

        //loop the productsArray and filter results using strpos (php)

 

0 Likes