4

I am using GET V1/products endpoint to fetch product list. I want to fetch sku and name only.

http://localhost/magento/rest/default/V1/products?searchCriteria[sortOrders][0][direction]=ASC&currencyCode=USD&searchCriteria[currentPage]=1&searchCriteria[pageSize]=10&fields=items[name,sku]

response

{
"items": [
    {
        "sku": "5245",
        "name": "Test Product"
    },
    {
        "sku": "product 1",
        "name": "product 1"
    },
    {
        "sku": "product 2",
        "name": "product 2"
    },
  ]
}

I am not getting total number of records in this response. I checked it on devdocs as well. It also has same type of response, please find link below.

Magento filtered response

Please help if anyone already faced this and solved it.

4

2 Answers 2

8

Ok I found the solution, I checked some core files of catalog module and I can see that search criteria and total records are not in items index so I just need to update my request like below.

http://localhost/magento/rest/default/V1/products?searchCriteria[sortOrders][0][direction]=ASC&currencyCode=USD&searchCriteria[currentPage]=1&searchCriteria[pageSize]=10&fields=items[name,sku],total_count

I hope it'll help others, Happy Coding :)

2
  • Welcome @AdityaShah Oct 22, 2018 at 8:45
  • Suthan, thanks for your answer, can you please help, how can we can available filters with the result? Apr 16, 2021 at 10:42
4

You need to select total count too to fetch it. Add total_count at the end of your request like this:

REQUEST,total_count
2
  • Thanks Kamal, I already found the solution and your solution is same what I did :) Oct 22, 2018 at 6:36
  • Welcome @AdityaShah Oct 30, 2018 at 17:32

Your Answer

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

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