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
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 '18 at 8:45
  • Suthan, thanks for your answer, can you please help, how can we can available filters with the result? Apr 16 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 '18 at 6:36
  • Welcome @AdityaShah Oct 30 '18 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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