cancel
Showing results for 
Search instead for 
Did you mean: 

API result error with searchCriteria in categories

API result error with searchCriteria in categories

HI,
I have a problem retrieving a category id.
The research I would like to do is made up of two criteria:
The name from the category and the parent_id
This is the example:

 

curl --location --globoff 'https://server/rest//V1/categories?searchCriteria[filterGroups][0][filters][0][field]=parent_id&searchCriteria[filterGroups][0][filters][0][value]=2&searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[filterGroups][1][filters][0][field]=name&searchCriteria[filterGroups][1][filters][0][value]=Acer&searchCriteria[filterGroups][1][filters][0][conditionType]=eq' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxx' 

As a result I get the list of all categories.
I expect either nothing if it doesn't exist or the id of the category I want to filter.

 

Where am I doing wrong?

2 REPLIES 2

Re: API result error with searchCriteria in categories

Hello @gbgssoftwad791 

 

It looks like your cURL command is correct, but there might be a problem with the syntax of your API request.

Try removing the double forward slash (//) in the URL after "rest/" so that it reads:

 

curl --location --globoff 'https://server/rest/V1/categories?searchCriteria[filterGroups][0][filters][0][field]=parent_id&searchCriteria[filterGroups][0][filters][0][value]=2&searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[filterGroups][1][filters][0][field]=name&searchCriteria[filterGroups][1][filters][0][value]=Acer&searchCriteria[filterGroups][1][filters][0][conditionType]=eq' \
--header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxx'

Additionally, make sure that you have the correct value for "server" in the URL, and that you have replaced "xxxxxxxxxxxxxxxxxxxx" in the Authorization header with a valid token.

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Re: API result error with searchCriteria in categories

First, there's an extra forward slash ("/") in the URL after "rest". It should be "https://server/rest/V1/categories" instead of "https://server/rest//V1/categories".

Secondly, in the cURL command, you are using the --globoff option, which disables URL globbing and prevents the square brackets in the query parameters from being treated as special characters. However, this option is not necessary in this case since the square brackets are already properly encoded in the URL.

Here's the corrected cURL command for your category search:

curl --location 'https://server/rest/V1/categories?searchCriteria[filterGroups][0][filters][0][field]=parent_id&searc...' --header 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxx'