Skip to main content

Filtering and Sorting

The Kojo API offers several options for sorting and filtering data.

These parameters are often used in combination with pagination.

Sorting​

Records may be sorted using the orderBy and direction parameters. The Kojo API supports sorting for every field that is a string, numeric, or datetime type.

When using pagination, sorting will be done across all records in the database, prior to paginating the records.

Example Query​

query {
jobs(
orderBy: code,
direction: ASC
) {
id
code
name
}
}

Querying With Filters​

Queries that return an array of entities can be filtered by various parameters within the queried data. The specific fields that support filtering are listed under the Parameters heading of each query that returns an array of data.

Filters are applied by combining a field name with the specific type of filter that is to be used. The datatype of the field determines which filters are available for the field.

For GraphQL filters, append the filter type to the end of the field name with an underscore. For example, the query below returns all orders with a purchaseOrderNumber that starts with "1-":

query {
orders(
filter: { purchaseOrderNumber_starts_with: "1-" }
) {
id
purchaseOrderNumber
}
}

For REST filters, filters are defined in query params. For example, the query below returns all orders with a purchaseOrderNumber that begins with "1-":

GET https://api.kojo.tech/orders?filter.purchaseOrderNumber_starts_with=1-

Multiple filters can be used simultaneously. See the examples below.

query {
orders(
filter: {
purchaseOrderNumber_starts_with: "1",
createdAt_lt: "2024-01-01T10:00:00.000Z"
}
) {
id
createdAt
purchaseOrderNumber
}
}
GET https://api.kojo.tech/orders?filter.purchaseOrderNumber_starts_with=1&filter.createdAt_lt=2024-01-01T10:00:00.000Z

Available Filtering Parameters​

The available filtering parameters depend on the datatype of the field defined in the filter.

String Field Filters​

Filter StringDescriptionExpected InputGraphQL ExampleREST Example
<field name>Field is equal to the provided stringStringcode: "100"?filter.code=100
notField is not equal to the provided stringStringcode_not: "100"?filter.code_not=100
inField matches a value in the provided arrayString[]code_in: ["100", "200"]?filter[integrationState_in]=ERROR&filter[integrationState_in]=LINKED OR ?&filter.integrationState_in=LINKING&filter.integrationState_in=LINKED
not_inField does not match a value in the provided arrayString[]code_not_in: ["100", "200"]N/A
containsField contains the provided stringStringcode_contains: "10"?filter.code_contains=10
not_containsField does not contain the provided stringStringcode_not_contains: "10"?filter.code_not_contains=10
starts_withField starts with the provided stringStringcode_starts_with: "10"?filter.code_starts_with=10
not_starts_withField does not start with the provided stringStringcode_not_starts_with: "10"?filter.code_not_starts_with=10
ends_withField ends with the provided stringStringcode_ends_with: "10"?filter.code_ends_with=10
not_ends_withField does not end with the provided stringStringcode_not_ends_with: "10"?filter.code_not_ends_with=10

Float/Int Field Filters​

Filter StringDescriptionExpected InputGraphQL ExampleREST Example
<field name>Field is equal to the provided numbernumberextPrice: 25?filter.extPrice=25
gtField is greater than the provided numbernumberextPrice_gt: 25?filter.extPrice_gt=25
gteField is greater than or equal to the provided numbernumberextPrice_gte: 25?filter.extPrice_gte=25
ltField is less than the provided numbernumberextPrice_lt: 25?filter.extPrice_lt=25
lteField is less than or equal to the provided numbernumberextPrice_lte: 25?filter.extPrice_lte=25

Boolean Field Filters​

Filter StringDescriptionExpected InputGraphQL ExampleREST Example
<field name>Field is equal to the provided booleannumbertaxExempt: true?filter.taxExempt=true
notField is the inverse of the provided booleanbooleantaxExempt_not: true?filter.taxExempt_not=true

ID Field Filters​

Filter StringDescriptionExpected InputGraphQL ExampleREST Example
idID is equal to the provided IDIDid: "clqzdedh90012b24xndju75yu"?filter.id=clqzdedh90012b24xndju75yu
inID matches a value in the provided arrayID[]id_in: ["clqzdedh90012b24xndju75yu", "clpkd1sgv0000uy4xzw6r90wi"]N/A
not_inID does not match a value in the provided arrayID[]id_not_in: ["clqzdedh90012b24xndju75yu", "clpkd1sgv0000uy4xzw6r90wi"]N/A

Enum/Scalar Field Filters​

Filter StringDescriptionExpected InputGraphQL ExampleREST Example
<field name>Field is equal to the provided enum valueEnumstate: DRAFT?filter.state=DRAFT
notField is not equal to the provided enum valueEnumstate_not: DRAFT?filter.state_not=DRAFT
inField is equal to a value in the provided array of enumsEnum[]state_in: [ACTIVE, DRAFT]N/A
not_inField is not equal to a value in the provided array of enumsEnum[]state_not_in: [ACTIVE, DRAFT]N/A

DateTime Field Filters​

Filter StringDescriptionExpected InputGraphQL ExampleREST Example
gtDate field is after the provided dateDateTimeupdatedAt_gt: "2024-01-25T15:30:00"?filter.updatedAt_gt=2024-01-25T15:30:00
gteDate field is after or equal to the provided dateDateTimeupdatedAt_gte: "2024-01-25T15:30:00"?filter.updatedAt_gte=2024-01-25T15:30:00
ltDate field is before the provided dateDateTimeupdatedAt_lt: "2024-01-25T15:30:00"?filter.updatedAt_lt=2024-01-25T15:30:00
lteField is less than or equal to the provided numberDateTimeupdatedAt_lte: "2024-01-25T15:30:00"?filter.updatedAt_lte=2024-01-25T15:30:00

When providing DateTime arguments to a filter, any of the following formats are accepted:

  • 2024-01-25
  • 2024-01-25T15:30:00
  • 2024-01-25T15:30:00.500
  • 2024-01-25T15:30:00.500Z
  • 2024-01-25T15:30:00.500-0400

Retrieving Records Based on Timestamp​

When integrating Kojo with another system, you may want to only get records that have been modified since your last sync. You can do this through the Kojo API by using the updatedAfter parameter. When using this parameter, Kojo will only return records that were created or updated after the specified time.

The updatedAfter parameter should be a UTC timestamp in the accepted date format. If the updatedAfter parameter is not provided, Kojo will return all records regardless of when they were last modified.