Skip to main content

Pagination, Metadata and Filtering

Many endpoints in the NERM API support a generic syntax for paginating, filtering, and sorting results. A collection endpoint has the following characteristics:

  • The HTTP verb is always GET.
  • The last component in the URL is a plural noun (ex. /users).
  • The return value from a successful request is always an array of JSON objects. This array may be empty if there are no results.

Paginating Results

Use the following optional query parameters to achieve pagination:

ParameterDescriptionDefaultConstraints
limitInteger specifying the maximum number of records to return in a single API call. If it is not specified, a default limit is used.100Maxiumum of 500 for api/profiles
offsetInteger specifying the offset of the first result from the beginning of the collection. The offset value is record-based, not page-based, and the index starts at 0. For example, offset=0 and limit=20 returns records 0-19, but offset=1 and limit=20 returns records 1-20.0Between 0 and the last record index.
orderString specifying the ascending order in which the results should be returned, for example, order=login would return the users results in an ascending alphanumeric order-Limited to specific parameters

Examples:

  • GET /api/users?limit=2
  • GET /api/users?limit=20&offset=4
  • GET /api/users?order=created_at

Metadata

Metadata can be added to a result to allow for progromatic approaches to fetching data.

NameDescriptionDefault
metadataBoolean that specifies wether or not to return a _metadata key with pagination informationfalse

Example:

  • GET /api/users?metadata=true
{
...
"_metadata": {
"limit": 100,
"offset": 200,
"total": 500,
"next": "api/users?offset=300&limit=100
}
}

Filtering Results

Resource attributes can be added to parameters to perform a basic match filter. Refer to each documented endpoints Query Parameters to identify what can be used.

Example:

Advanced Profile Filtering

More advanced filtering can be performed on profiles by using the Advanced Search Endpoint.

For example, if you wanted to find all profiles where the personal_first_name started with the letter "a", you would first need to find the id of the personal_first_name attribute, and provide a JSON body like so:

{
"advanced_search": {
"condition_rules_attributes: [
{
"type": "ProfileAttributeRule",
"condition_object_id": <id of the personal_first_name attribute>,
"object_type": "NeAttribute",
"comparison_operator": "start_with?",
"value": "a"
}
]
}
}

You can also provide multiple filters in the same call. For example, you want to find all profiles that are not Active, that have a specific department profile. First you need to find the id of the attribute that contains that profile, and then the id of the specific department profile. Then provide a JSON body like so:

{
"advanced_search": {
"condition_rules_attributes: [
{
"type": "ProfileStatusRule",
"comparison_operator": "!=",
"value": "Active"
},
{
"type": "ProfileAttributeRule",
"condition_object_id": <id of the department attribute>,
"object_type": "NeAttribute",
"comparison_operator": "include?",
"value": <id of the department profile>
}
]
}
}

There are 3 types of condition_rules_attributes

ProfileStatusRule

This rule searches for profiles based on the status.

KeyTypeDescription
idstringIf you are updating an existing rule, include the ID of that rule, if you do not include an ID it will create a new condition rule
typestring requiredThe value must be 'ProfileStatusRule'
comparison_operatorstring requiredThis is how the comparison is made for the attribute values.
Available basic operators:
  • == (equals)
  • != (not equal)
valuestring requiredThis is the value used for comparison.0
Available Values:
  • Active
  • Inactive
  • Leave of absence
  • Terminated
_destroybooleanSupplying this option with "true" will cause the condition to be destroyed

Example:

{
"advanced_search": {
"condition_rules_attributes": [
{
"type": "ProfileStatusRule",
"comparison_operator": "==",
"value": "Active"
}
]
}
}

ProfileTypeRule

This rule searches for profiles based on the id of the profile type.

KeyTypeDescription
idstringIf you are updating an existing rule, include the ID of that rule, if you do not include an ID it will create a new condition rule
typestring requiredThe value must be 'ProfileTypeRule'
comparison_operatorstring requiredThis is how the comparison is made for the attribute values. Available basic operators:
  • == (equals)
  • != (not equal)
valuestring requiredThis is the value used for comparison. This should be the ID of the profile type
_destroybooleanSupplying this option with "true" will cause the condition to be destroyed

Example:

{
"advanced_search": {
"condition_rules_attributes": [
{
"type": "ProfileTypeRule",
"comparison_operator": "==",
"value": "1bd99a83-57e1-4e3c-bbb0-861b4700cff6"
}
]
}
}

ProfileAttributeRule

This rule searches for profiles based on an attribute that profile has.

KeyTypeDescription
idstringIf you are updating an existing rule, include the ID of that rule, if you do not include an ID it will create a new condition rule
typestring requiredThe value must be 'ProfileAttributeRule'
object_typestring requiredThe values must equal 'NeAttribute'
condition_object_idstring requiredthis is the id of the attribute you are searching against
comparison_operatorstring requiredThis is how the comparison is made for the attribute values.
Available basic operators:
  • == (equals)
  • != (not equal)
  • > (greater than)
  • < (less than)
  • start_with? (starts with)
  • end_with? (ends with)
  • include? (includes)
Available date operators:
  • before (before specific date)
  • after (after specific date)
  • > (more than X days before/after today)
  • < (less than X days before/after today)
  • == (equal to X days before/after today)
valuestring requiredThis is the value used for comparison.
Value formatting:
  • profile select attribute: ID of profile
  • profile search attribute: ID of profile
  • user select attribute: ID of user
  • user search attribute: ID of user
  • date attribute (before, after): correct date format for attribute
  • date attribute (>, <, ==): "X before" or "X after" where X is the number of days
_destroybooleanSupplying this option with "true" will cause the condition to be destroyed

Example:

{
"advanced_search": {
"condition_rules_attributes": [
{
"type": "ProfileAttributeRule",
"condition_object_id": "4ba5be36-3c4d-11ee-be56-0242ac120002",
"object_type": "NeAttribute",
"comparison_operator": "includes?",
"value": "term"
}
]
}
}