Skip to main content

Sorting

Request

Method: POST

Endpoint: /v1.4/search

Fields

FieldTypeRequiredDefaultDescription
customer_idStringYesRandom unique customer id generate by PA tracker
website_idStringYesClient unique website id provided by PA
qStringYesInput search query string
clientStringYesUnique client shortcode provided by PA
startIntegerYesDefines the offset from the first result you want to fetch
sizeIntegerNo20The max number of results you want returned with your query
sort_fieldsObject ArrayNoRelevance ScoreSorting search results based on item's numeric and text attributes. Multiple attributes sorting is supported. Sorting of numeric custom attribute are also supported

Examples

Example 1 - Sort the results by a field named sale_price of type number in ascending order.

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"sort_fields":[{"sale_price":{"order":"asc", "type": "number"}}]
}'

Example 2 - Sort the results by a field named org_price of type number in descending order.

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"sort_fields":[{"org_price":{"order":"desc", "type": "number"}}]
}'

Example 3 - Sort the results by org_price followed by a field named title of type text in ascending order.

curl --location 'https://<PA_SEARCH_END_POINT>/v1.4/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer cGFTZXXXXXXXXXXXXXXXA==' \
--data '{
"customer_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"website_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"q": "SEARCH STRING",
"client": "CLIENT SHORTCODE",
"start": 0,
"size": 1,
"sort_fields":[{"org_price":{"order":"desc", "type": "number"}, {"title":{"order":"asc", "type": "text"}}}]
}'

Response

{
"payload": {
***,
"result": [
{
***,
"availability": -1,
"org_price": "10"
"title": "Sample item 1",
***
},
{
***,
"availability": -1,
"org_price": "9"
"title": "Sample item 2",
***
},
{
***,
"availability": 0,
"org_price": "11"
"title": "Sample item 3",
***
},
{
***,
"availability": 0,
"org_price": "10"
"title": "Sample item 4",
***
}
],
"total_results": 50,
"suggestions" : {***},
"redirects" : {***}
},
"type": 1
}