This section will teach you how to sort our collection endpoints!
sortOrder and sortField
sortOrder and sortFieldBy default, our getAll endpoints will accept sorOrder and sortField as query parameters.
| Query Params | Type | Default | Allowed Values | Purpose |
|---|---|---|---|---|
sortOrder | string | "ASC" | "ASC","DESC" | Specify whether the collection is in ascending or descending order |
sortField | string | Depends on the endpoint | Depends on the endpoint | Specify which field is used for sorting |
Some examples using the List All Employees endpoint are given below.
Example 1: No sortOrderor sortField
sortOrderor sortField{
"data": [
{
"empNumber": 2,
"lastName": "Crowder",
"firstName": "Edwyn",
"middleName": "Treyvon",
"employeeId": "0002",
"terminationId": null
},
{
"empNumber": 4,
"lastName": "Dell",
"firstName": "Alysia",
"middleName": "Lianna",
"employeeId": "0004",
"terminationId": null
},
{
"empNumber": 1,
"lastName": "Kasper",
"firstName": "Trystan",
"middleName": "Alfonso",
"employeeId": "0001",
"terminationId": null
},
{
"empNumber": 3,
"lastName": "Rankin",
"firstName": "Quinlan",
"middleName": "Jacques",
"employeeId": "0003",
"terminationId": null
}
],
"meta": {
"total": 4
},
"rels": []
}
For this particular endpoint, the default sortField is employees.lastName. Since the order is ascending by default the collection given above, having the last name sorted in ascending order, is received.
Example 2: With sortOrder=DESC
sortOrder=DESC{
"data": [
{
"empNumber": 3,
"lastName": "Rankin",
"firstName": "Quinlan",
"middleName": "Jacques",
"employeeId": "0003",
"terminationId": null
},
{
"empNumber": 1,
"lastName": "Kasper",
"firstName": "Trystan",
"middleName": "Alfonso",
"employeeId": "0001",
"terminationId": null
},
{
"empNumber": 4,
"lastName": "Dell",
"firstName": "Alysia",
"middleName": "Lianna",
"employeeId": "0004",
"terminationId": null
},
{
"empNumber": 2,
"lastName": "Crowder",
"firstName": "Edwyn",
"middleName": "Treyvon",
"employeeId": "0002",
"terminationId": null
}
],
"meta": {
"total": 4
},
"rels": []
}
Now the collection is sorted in descending order of last names.
Example 3: With sortField=employee.employeeId
sortField=employee.employeeId{
"data": [
{
"empNumber": 1,
"lastName": "Kasper",
"firstName": "Trystan",
"middleName": "Alfonso",
"employeeId": "0001",
"terminationId": null
},
{
"empNumber": 2,
"lastName": "Crowder",
"firstName": "Edwyn",
"middleName": "Treyvon",
"employeeId": "0002",
"terminationId": null
},
{
"empNumber": 3,
"lastName": "Rankin",
"firstName": "Quinlan",
"middleName": "Jacques",
"employeeId": "0003",
"terminationId": null
},
{
"empNumber": 4,
"lastName": "Dell",
"firstName": "Alysia",
"middleName": "Lianna",
"employeeId": "0004",
"terminationId": null
}
],
"meta": {
"total": 4
},
"rels": []
}
Now the sortField has been changed to employeeId and the collection is sorted in ascending (default) order of employee IDs.