cancel
Showing results for 
Search instead for 
Did you mean: 

Search Criteria provides irrelevant data

Search Criteria provides irrelevant data

My requirement is to fetch the products which have updated after a given time. But those should belong the store view code I provide from the store_id header. For an example after the given time I have updated 2 products. One is included only in the sample website whose store view code is "swsv1". Other updated product is included only in the main website whose store view code is default. But in my requirement I need to fetch only product data which have updated after the given time, but should be there in the "swsv1" store view. So for this I tried this curl request.

curl --location --globoff 'https://{{host}}/rest/swsv1/V1/products?searchCriteria[pageSize]=20&searchCriteria[currentPage]=1&searchCriteria[filterGroups][0][filters][0][field]=store_id&searchCriteria[filterGroups][0][filters][0][value]=swsv1&searchCriteria[filter_groups][1][filters][0][field]=updated_at&searchCriteria[filter_groups][1][filters][0][value]=2025-08-15%2002%3A27%3A45&searchCriteria[filter_groups][1][filters][0][condition_type]=gt' \
--header 'Authorization: Bearer {{accessToken}}' \
--header 'Content-Type: application/json' \
--header 'Cookie: PHPSESSID=v59gqflt7hmkl26fu46h75vks4; PHPSESSID=v59gqflt7hmkl26fu46h75vks4; private_content_version=f66a0c75cf4d0ccb1d00fef2eadde95c'

But this this request returned me both the products even the product which is associated with the default store view code, not the "swsv1" store view code. Could you please help me to resolve this?

Note that I can't use any 3rd party web hook mechanisms as "magento2" doesn't support a native web hook to get the product updates. So that's why I just tried this API call to get the product updates. If there is any mechanism to get the product updates of a store view code, without using any other dependencies highly appreciated.

2 REPLIES 2

Re: Search Criteria provides irrelevant data

Hi @dulithsena0ae6 ,

You can try below options

 

1) Resolve store code > numeric IDs (store id and website id)

Call the store API to find store_id and website_id for swsv1:

curl -s -H "Authorization: Bearer <ADMIN_TOKEN>" \
"https://<host>/rest/V1/store/storeViews"

Look for the object where "code":"swsv1" - it contains id (store_id) and website_id. (You can also call /rest/V1/store/storeGroups depending on what you need.)

 

2) Filter products by website_id

Use the numeric website_id in your searchCriteria. Example (single-line, URL-encoded):

curl --location --globoff \
"https://<host>/rest/all/V1/products?searchCriteria[filter_groups][0][filters][0][field]=website_id&searchCriteria[filter_groups][0][filters][0][value]=<WEBSITE_ID>&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[filter_groups][1][filters][0][field]=updated_at&searchCriteria[filter_groups][1][filters][0][value]=2025-08-15%2002%3A27%3A45&searchCriteria[filter_groups][1][filters][0][condition_type]=gt" \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json"

Replace <WEBSITE_ID> with the numeric website id you got in step 1.

/rest/all/ to make the filtering behavior explicit; you can also call from /rest/swsv1/ but the important filter is website_id.

 

3) Filter by store_id instead

If you need strictly the store-view assignment (numeric store id), you can use field=store_id&value=<STORE_ID>&condition_type=eq. Make sure <STORE_ID> is the numeric id from the storeViews response (not the store code). The same caveat about the store URL applies.

Reference: https://magento.stackexchange.com/questions/174620/magento-2-rest-api-accessing-products-based-on-st...

 

Problem Solved? Accept as Solution!

 

Thanks,

Ankit

Ankit Jasani

Re: Search Criteria provides irrelevant data

It looks like the issue is with how the filters are grouped in your search Criteria Magento sometimes ignores multiple filter groups unless properly nested. I had a similar problem and fixing the filter logic made it precise, felt as smooth as using Winbuzz to get exactly what you need.