Search code examples
restsearchmagento-2.0

Magento2 REST Search "Query does not exists"


I am on Mangento 2.0.3 CE and I'm trying to call the /search REST API.

With this request :

/rest/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filterGroups][0][filters][0][field]=name&searchCriteria[filterGroups][0][filters][0][value]=%test%&searchCriteria[filterGroups][0][filters][0][condition_type]=like

I get this error :

{
  "message": "Query quick_search_container does not exist",
  "trace": "#0 vendor/magento/framework/Search/Request/Mapper.php(94): Magento\\Framework\\Search\\Request\\Mapper->mapQuery('quick_search_co...')\n#1 vendor/magento/framework/Search/Request/Builder.php(183): Magento\\Framework\\Search\\Request\\Mapper->getRootQuery()\n#2 vendor/magento/framework/Search/Request/Builder.php(141): Magento\\Framework\\Search\\Request\\Builder->convert(Array)\n#3 vendor/magento/framework/Search/Search.php(71): Magento\\Framework\\Search\\Request\\Builder->create()\n#4 [internal function]: Magento\\Framework\\Search\\Search->search(Object(Magento\\Framework\\Api\\Search\\SearchCriteria))\n#5 vendor/magento/module-webapi/Controller/Rest.php(265): call_user_func_array(Array, Array)\n#6 vendor/magento/module-webapi/Controller/Rest.php(160): Magento\\Webapi\\Controller\\Rest->processApiRequest()\n#7 var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#8 vendor/magento/framework/App/Http.php(115): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#9 vendor/magento/framework/App/Bootstrap.php(258): Magento\\Framework\\App\\Http->launch()\n#10 index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http))\n#11 {main}"
}

If I remove the search?searchCriteria[requestName]=quick_search_container from the query I get this error Request name not defined.

I have one category "CatTest" set and one simple product "ProdTest" which should appear in the result.

Anyone knows how to resolve this error ?

[EDIT]

After digging a bit more I found out that in the class vendor/magento/framework/Search/Request/Builder.php l.137, the clean method whipout the $data var. Which then provoc the given exception.


Solution

  • Actually the problem came from my request which was wrong.

    For the search API a correct request is (to be converted to a GET request) :

    {
        "searchCriteria" : {
            "requestName": "quick_search_container",
            "filterGroups": [
                {
                    "filters": [
                        {
                            "field": "search_term",
                            "value": "*"
                        }
                    ]
                }
            ],
            "current_page": 1,
            "page_size": 20
        }
    }