4

How to get items using search rest apis,example: I want to search watch in mogento2,how can i get the data from rest apis.

Tried like this : http://localhost/magento2/index.php/rest/V1/search?searchCriteria[requestName]=watch

But i gives an error message like this:

{"message":"Request name 'watch' doesn't exist"}.

Actually watches data is there.

2 Answers 2

8

Try:

http://localhost/magento2/index.php/rest/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filterGroups][0][filters][0][field]=search_term&searchCriteria[filterGroups][0][filters][0][value]=watch

The possible values for requestName include;

  • quick_search_container
  • advanced_search_container
  • catalog_view_container

Note: The filters vary for each requestName, see Magento/CatalogSearch/etc/search_request.xml for more details.

1
  • 2
    Wow.. now that´s a useless response! :D (From a frontend point of view) ;) Guess we will need a custom api for this as well :/
    – Mackelito
    Commented Oct 4, 2016 at 8:47
0

Pass the correct params to make work search API.

Method: GET

Request URL: http://localhost/magento2/rest/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filterGroups][0][filters][0][field]=search_term&searchCriteria[filterGroups][0][filters][0][value]=watch

Params:

  searchCriteria[requestName]                        = quick_search_container
  searchCriteria[filterGroups][0][filters][0][field] = search_term
  searchCriteria[filterGroups][0][filters][0][value] = watch

Response:

{
    "items": [
        {
            "id": 44,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "80.6521797180175800"
                }
            ]
        },
        {
            "id": 40,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "80.6521797180175800"
                }
            ]
        },
        {
            "id": 43,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "76.1715030670166000"
                }
            ]
        },
        {
            "id": 42,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "76.1715030670166000"
                }
            ]
        },
        {
            "id": 41,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "76.1715030670166000"
                }
            ]
        },
        {
            "id": 39,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "76.1715030670166000"
                }
            ]
        },
        {
            "id": 38,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "76.1715030670166000"
                }
            ]
        },
        {
            "id": 37,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "76.1715030670166000"
                }
            ]
        },
        {
            "id": 36,
            "custom_attributes": [
                {
                    "attribute_code": "score",
                    "value": "76.1715030670166000"
                }
            ]
        }
    ],
    "aggregations": {
        "buckets": [
            {
                "name": "category_bucket",
                "values": [
                    {
                        "value": "3",
                        "metrics": [
                            "3",
                            "9"
                        ]
                    },
                    {
                        "value": "6",
                        "metrics": [
                            "6",
                            "9"
                        ]
                    },
                    {
                        "value": "7",
                        "metrics": [
                            "7",
                            "4"
                        ]
                    },
                    {
                        "value": "8",
                        "metrics": [
                            "8",
                            "4"
                        ]
                    }
                ]
            }
        ],
        "bucket_names": [
            "category_bucket"
        ]
    },
    "search_criteria": {
        "request_name": "quick_search_container",
        "filter_groups": [
            {
                "filters": [
                    {
                        "field": "search_term",
                        "value": "watch",
                        "condition_type": "eq"
                    }
                ]
            }
        ]
    },
    "total_count": 9
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.