Query
Find clients, jobs, requests, visits or custom object records that match a set of conditions, including conditions on related records.
The Query API finds records that match conditions you describe in the request body. Use it for questions a list filter cannot answer, such as "clients with no completed job in the last year".
| Route | Use it for | Scope |
|---|---|---|
POST /api/v1/query | Run a query. | The read scope of every record type the query touches. |
GET /api/v1/query/metadata | See which record types, fields and operators you can use. | objects:read |
For a plain list or an incremental sync, the list routes are simpler: see Clients or Custom objects.
Run a query
curl -X POST https://api.fieldcamp.ai/api/v1/query \
-H "Authorization: Bearer $FIELDCAMP_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"entity": "client",
"filters": {
"all": [
{
"related": {
"entity": "job",
"via": "clientId",
"where": {
"all": [
{ "field": "jobStatus", "op": "equals", "value": "completed" },
{ "field": "updatedAt", "op": "within_past_days", "value": 365 }
]
}
},
"exists": false
}
]
},
"limit": 50
}'This returns clients that have no job completed in the past 365 days.
| Field | Description |
|---|---|
entity | client, job, request, visit, or a custom object slug. |
filters | The conditions. See below. |
limit | 1–100, default 50. |
cursor | meta.next.cursor from the previous response, unchanged. |
withTotal | true adds meta.total, the exact number of matching records. |
The response is the same as a list route: data is the records and
meta.next is null on the last page.
Conditions
filters is a tree. A group is { "all": [...] } (every condition must
match) or { "any": [...] } (at least one). Groups can contain groups.
A condition on a field:
{ "field": "jobStatus", "op": "equals", "value": "completed" }A condition on related records:
{ "related": { "entity": "job", "via": "clientId", "where": { "all": [] } }, "exists": true }exists: true matches when at least one related record fits where;
exists: false matches when none does. via is the field on the related
record that points back. where is optional.
Operators:
| Operator | Meaning |
|---|---|
equals, not_equals | Exact match. |
in, not_in | value is a list. |
contains | Text contains value. |
gt, gte, lt, lte | Greater or less than, for numbers and dates. |
is_empty, is_not_empty | The field has no value, or has one. |
within_past_days, older_than_days | For dates; value is a number of days. |
GET /api/v1/query/metadata lists the operators that make sense for each
field. The API does not enforce this: an operator that does not suit the
field is accepted and usually returns no records.
Limits: a tree deeper than 5 levels, or with more than 40 conditions, is
refused. A related condition cannot contain another related condition
inside its where.
Discover fields
GET /api/v1/query/metadata returns, for each record type on the account:
| Field | Description |
|---|---|
entity, label | The value to send as entity, and its display name. |
fields | Each with label, type and ops — the operators that suit it. |
relations | The entity and via pairs you can use in a related condition. |
Custom objects and their fields are included.
Errors
| Status | Code | When |
|---|---|---|
422 | VALIDATION_ERROR | An unknown operator, a missing entity, a wrong value type for the operator, or a tree past the limits. |
400 | INVALID_CURSOR | The cursor is not a valid cursor value. |
400 | INVALID_JSON | The body is not valid JSON. |
403 | — | The key is missing the read scope of a record type in the query. |
Field and record type names are not checked
A misspelled field name, or an entity that does not exist on the account,
is not an error: the query returns no records. If a query comes back empty
unexpectedly, check the names against GET /api/v1/query/metadata.
Endpoints
/api/v1/queryAuthorization
BearerAuth JWT from POST /api/auth/login (response.data.token). Tokens do not expire.
In: header
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
curl -X POST "https://example.com/api/v1/query" \ -H "Content-Type: application/json" \ -d '{ "entity": "string" }'{}/api/v1/query/metadataAuthorization
BearerAuth JWT from POST /api/auth/login (response.data.token). Tokens do not expire.
In: header
Response Body
application/json
application/json
application/json
curl -X GET "https://example.com/api/v1/query/metadata"{}