Search API - sort_by not working
Hi Team,
I am SFCC Developer and working on SFRA project currently.
We are currently integrating Search API to get the images from specific folder.
When we try to add sort_by to URL parameter, its throwing below error.
{ "error": { "message": "Incorrect sort format \"[{\\\"filename\\\":\\\"asc\\\"}]\", supported format [{\"created\":\"desc\"}]" } }
Also we tried sending the the sort_by as body parameter, endpoint is not considering the body parameters and returning un-expected response. Below body parameters.
Request:
{ "expression": "resource_type:image AND folder=tanagra/sfcc_image_automation", "sort_by": [ { "filename": "asc" } ], "max_results": 2 }
Response should contain only 4 total count and 2 max assets But its returning below.
Response:
{ "total_count": 63584, "time": 212, "resources": [ { and so on.....
Please help us to resolve this issue. Suggest us how to use sort_by field in Search API.
-
Official comment
Hi Suryarao.
Thanks for getting in touch.
It looks like when you're sending the body to the Search API, it's being sent as plain text. I just created the folder "tanagra/sfcc_image_automation" on my account and uploaded two images. Running your search query exactly as you have specified above, but with the content-type header set to application/json via curl, I get just two results returned. If I send the body without specifying the content-type, the full contents of my cloud are returned.
Can you please ensure you're sending the payload of the POST request as json?
Many thanks,
-Danny -
Hi Danny,
Thank you so much for your reply.
After we change the GET request to POST request, it started working.
Thanks,
Surya
0 -
That's great to hear, Surya!
If you encounter any more issues or have any other questions then please feel free to raise a support ticket, and we'll be happy to help.
Many thanks,
-Danny0
Post is closed for comments.
Comments
3 comments