If the get
endpoint is exposed to a resource, you can query for a collection of records for that resource.
GET https://services.trade-traks.ca/api/User/get
Parameter | Type | Value |
---|---|---|
filters |
JSON | JSON formatted array of filters. See Filters section below for more information |
include |
JSON | JSON formatted array of related resources to be sent with the result set. |
orders |
JSON | JSON formatted array of orders to determine sort order of the collection.
Example:
|
fields |
JSON | JSON formatted array of field names. When this parameter is present, the collection results will only contain the fields specified.
Example
|
page |
Integer | The current page to return in the result set. If not present, ALL records will be returned in most cases. |
custom_page_limit |
Integer | Allows you to set a custom page limit to over-ride the default number of records returned per page. Must be smaller than the default page setting. |
limit |
Integer | Allows you to limit the result set to a specified number of records. |
count |
Boolean | If set to true, a count property is returned which indicates the total number of records in the result set. No data is returned. |
GET https://services.trade-traks.ca/api/User/get?orders=[["first_name","ASC"]]&page=12
Related resources can be included within a parent collection, by using the include
parameter. For example:
GET https://services.trade-traks.ca/api/Job/get
with the following include parameter:
["User"]
Would return the following JSON structure:
{
data: [
{
id: 321,
job_name: "Lighting Installation",
... (other job fields),
User: [
{
id: 2,
first_name: "Chad",
last_name: "Tiffin",
... (other user fields)
}
]
}
],
success: true
}
Note the User
property on the result object, which has been appended to each Job
record in the collection.
include = [
{
model: "User",
fields: ["slug","first_name","last_name"],
include: ["ProfileImage"]
}
]
NOTE: You can nest as deeply as needed, however be aware that deeply nested queries can significantly affect performance.
Sometimes there may be several relations of the same resouce on a record. For example, the Service
resource owns multiple User
child relations, that are attached using explicit keys to differentiate them: AssignedTo
, UpdatedBy
, WorkCompletedBy
. Calling the User
resource in an include to Service
will attach all of these children relations to the record -- which may not be desirable for performance reasons.
Therefore you can use the omit
key to pick and choose which relations of a specific resource you would like included:
include = [
{
model: "User",
omit: ["WorkCompletedBy","AssignedTo"]
}
]
Filtering is accomplished by sending a JSON formatted array of filters in filters
parameter.
It accepts any of the following formats, in any combination:
[{field}, {value}]
[{field} {operator}, {value}]
Accepted operators:
or
statements together:
[{field}, {value}, 'or']
LIKE
comparison. SQL equivelant is LIKE '%value%':
[{field}, {value},'and/or','like']
[{field}, [{value1},{value2},...]]
These filters must be sent in a JSON formatted array, and can include any number or combination of filters:
[
["first_name", "Chad"],
["first_name", "Jason","or"]
]
[
["first_name", ["Chad","Jason"]],
]
[
["age >", 18], //age must be greater than 18
["age <=",65], //age must also be less than or equal to 65
["eye_color","brown"] //eye_color must also be brown
]
Job
object, which has child User
records. The following example would return only Job
records with containing User
records that match the given filters:
[
["User.first_name","Chad"],
["User.first_name","Chad","or","like"]
]
match-all
:
[
["User.first_name","Chad"],
["User.first_name","Chad","or",false,"match-all"]
]
[
["User",false]
]
Each filter accepts the following parameters:
[ {Field} {Operator} (optional), {Matching Value}, {Logical Operator} (optional), {Comparison Type}, {Matching Scheme}]
Parameter | Accepted Values | Example |
---|---|---|
Field (required) |
|
Querying an included Child resource:
Match any possible values:
|
Operator |
|
|
Matching Value (required) | String, Number, Array, Datetime String | |
Logical Operator |
|
|
Comparison Type |
|
Will return all records with first_name field containing 'will' within the value. SQL equivelant of
|
Matching Scheme |
|
This will only return a result if All of the child Contact resource records have a name of 'Chad'
|