Exact Search vs Contains Search Product Api

Tourist
8 0 10

Trying to use the Admin Rest Api to search products by title and return a list of products.


In this version of the API: 2019-04, any search provided to the api, provides a contains result.  You can search for a term like "heavy" and get a result of "Independent Heavyweight Hoodie".

 

But in this version of the API: 2019-07 the exact same call returns results only for exact match.  There is no mention that this is intentional that I can find in the documentation, so maybe it's a bug?  

 

Anyone else see this problem or know a potential solution?  Thank you in advance!

2 Likes

Hello 

Yes, in API: 2019-07 we need to search for exact match. There is no options to search result by partial text.

Want to modify or incorporate custom changes on store, Hire us.
If helpful then please Like and Accept Solution .
Email: pallavi@oscprofessionals.com
Skype : oscprofessionals-87
Free Review and advice for sale on store | Shopify Private App | Custom Theme Development | Custom Modifications In To Shopify Theme | SEO & Digital Marketing | Site Speed Optimization | Performance Site Audit
0 Likes

Requests that pass a value for title will match only if the value is the same as the complete title. Partial matches aren't supported in Admin Product API version 2019-07 and 2019-10
Means You will pass product title name completely not partial because partial title is not supported while filter in API Version 2019-07 and 2019-10

EX : Your product title is : bla bla

So Your Admin product filter API like below

admin/api/2019-07/products.json?title=bla bla

above is the answer for below link

https://community.shopify.com/c/Shopify-APIs-SDKs/Exact-Search-vs-Contains-Search-Product-Api/m-p/580363
Want to modify or incorporate custom changes on store, Hire us.
If helpful then please Like and Accept Solution .
Email: pallavi@oscprofessionals.com
Skype : oscprofessionals-87
Free Review and advice for sale on store | Shopify Private App | Custom Theme Development | Custom Modifications In To Shopify Theme | SEO & Digital Marketing | Site Speed Optimization | Performance Site Audit
0 Likes
Tourist
8 0 10

Any idea why this change was made or how/where Shopify notified the community about this?

 

It's not clear to me why they wouldn't support a search by product name, as that seems like a common user need. 

 

It is also supported in the Shopify UI?!

2 Likes
Tourist
8 0 10

Is there any solution where user can contains search on product title via the new APIs?

 

Considering the Shopify UI uses contains for product searches, it's baffling to me that they would offer it in previous versions of their API, then remove it in more recent versions, when they clearly know it's valuable.  Search by exact name doesn't even make sense, as any developer would use id for that type of lookup and no human user is going to know the EXACT name and spelling of their products.

2 Likes
Tourist
7 0 4

This is a deal breaker, do you want partners to keep all products in sync needlessly on their systems and index them for searches just so they can provide users of their plugins the ability to let users select a product after searching one.

 

And I agree with the author here, this search is already available in admin panels, why is it removed from API?

2 Likes
Tourist
5 0 1

I agree that this is frustrating. Shopify should do a better job making it clear how they expect users of the latest versions of the REST Admin API to search for product. They imply that it's possible in their pagination results documentation .

 

A request that includes the page_info parameter can't include any other parameters except for limit. If you want your results to be filtered by other parameters, then you need to include those parameters in the first request you make.

 

I'll hold out some hope that there is a magic combination of attributes one can pass that will work and maybe a staffer will clarify for us.

 

In the meantime however it appears you can do a partial search using the GraphQL so I'll be giving that a try instead. https://community.shopify.com/c/Shopify-APIs-SDKs/GraphQL-search-for-products-based-on-description/m...

1 Like
Tourist
5 0 1

Update: Reading through the Release Notes for Product explicitly says that partial searches aren't supported

 

Requests that pass a value for title will match only if the value is the same as the complete title. Partial matches aren't supported.

However in that same section, it references the endpoint `/products/search` which I don't see documented in the admin api docs. Does anyone have info on how to use that endpoint?

 

Removed the page filter, and replaced page-based pagination with cursor-based pagination for GET /admin/api/2019-07/products/search.json

 

0 Likes
Shopify Partner
137 8 20

I just tried this and it was a "loose" search results set that was passed back in the API response. Here was my API query:

 

GET https://{myShop}.myshopify.com/admin/products.json?title=test 

The results set that came back included any products that had the word test in them. Not just the products that only had the word test in them. Like below...

 

{"products":[{"id":4360783429684,"title":"Publish Scope Test","body_html":"\u003cstrong\u003eHello World!\u003c\/strong\u003e","vendor":"Diamond Cellar","product_type":"Test","created_at":"2019-11-19T15:03:47Z","handle":"publish-scope-test","updated_at":"2019-11-19T15:16:48Z","published_at":null,"template_suffix":"","tags":"","published_scope":"global","admin_graphql_api_id":"gid:\/\/shopify\/Product\/4360783429684","variants":[{"id":31265108754484,"product_id":4360783429684,"title":"Default Title","price":"0.00","sku":"","position":1,"inventory_policy":"deny","compare_at_price":null,"fulfillment_service":"manual","inventory_management":"shopify","option1":"Default Title","option2":null,"option3":null,"created_at":"2019-11-19T15:03:47Z","updated_at":"2019-11-19T15:16:47Z","taxable":true,"barcode":"","grams":0,"image_id":null,"weight":0.0,"weight_unit":"lb","inventory_item_id":32769826947124,"inventory_quantity":0,"old_inventory_quantity":0,"requires_shipping":true...

Since I am not specifying the API version in my URI I assume that it would be hitting the latest production version, API 2019-10, correct?

1 Like
Highlighted
Tourist
5 0 1

Thanks for the extra info @Greg_Kujawa. I was able to confirm the same. I was originally using the 2019-10 and 2019-07 API versions in the URL. Removing that worked for my search `title=2020 courses`.

 

Then I started testing all the API versions again and found success when I tried 2019-04

 

GET https://{{shop}}.myshopify.com/admin/api/2019-04/products.json?title=2020 courses

 

This makes sense given that the release notes for the `2019-04` version state that it is the "base version of the REST and GraphQL Admin APIs". That means this will most likely no longer work with the release of the `2020-04` version in April.

0 Likes