Skip to Content
API and MCPResources

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".

RouteUse it forScope
POST /api/v1/queryRun a query.The read scope of every record type the query touches.
GET /api/v1/query/metadataSee 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.

FieldDescription
entityclient, job, request, visit, or a custom object slug.
filtersThe conditions. See below.
limit1–100, default 50.
cursormeta.next.cursor from the previous response, unchanged.
withTotaltrue 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:

OperatorMeaning
equals, not_equalsExact match.
in, not_invalue is a list.
containsText contains value.
gt, gte, lt, lteGreater or less than, for numbers and dates.
is_empty, is_not_emptyThe field has no value, or has one.
within_past_days, older_than_daysFor 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:

FieldDescription
entity, labelThe value to send as entity, and its display name.
fieldsEach with label, type and ops — the operators that suit it.
relationsThe entity and via pairs you can use in a related condition.

Custom objects and their fields are included.

Errors

StatusCodeWhen
422VALIDATION_ERRORAn unknown operator, a missing entity, a wrong value type for the operator, or a tree past the limits.
400INVALID_CURSORThe cursor is not a valid cursor value.
400INVALID_JSONThe 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

POST/api/v1/query

Authorization

BearerAuth
AuthorizationBearer <token>

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"  }'
{}
GET/api/v1/query/metadata

Authorization

BearerAuth
AuthorizationBearer <token>

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"
{}

On this page