Queries (v3)

Learn how to use the v3 query endpoint to search, filter, sort, aggregate, and paginate records using a structured JSON body.

📘

Please note

This guide explains how to use the v3 query endpoint. For the reference page where you can try out queries, click here.


Overview

The v3 query endpoint (POST /api/v3/query) accepts a structured JSON body and returns matching records from any object in your CRM. It supports filtering with logical operators, sorting, pagination, aggregation functions, and grouping.


Request body

PropertyTypeRequiredDefaultNotes
objectTypeintegerYesThe numeric object type code to query.
fieldsarray of fieldYesAt least one field must be specified.
filterarray of conditionGroupNoFilter conditions to apply.
orderByarray of orderByNoFields to sort results by.
groupByarray of groupByNoFields to group results by. Required when using aggregation functions.
pageNumberintegerNo1Must be a positive integer.
pageSizeintegerNo25Valid range: 1–500.
📘

Query modes

The query operates in two modes depending on whether groupBy is provided:

  • Simple mode (no groupBy): returns individual records. aggrFunc and alias on fields have no effect.
  • Aggregation mode (with groupBy): returns grouped results. Fields must either appear in groupBy or have an aggrFunc. All orderBy fields must also appear in groupBy.

objectType

This property must be a valid object type code that exists in your system.

StatusError
400 Bad RequestInvalid objectType: {objectType}
403 ForbiddenUser has no read permissions

fields

A field object describes which fields to include in the response, and optionally how to aggregate them.

PropertyTypeRequiredNotes
namestringYesA valid field name. May also be a related field using an underscore (_) between the lookup field name and the related field name (e.g. ownerid_fullname).
aliasstringNoAn alias for the aggregated field in the result set. Only used when aggrFunc is specified; ignored otherwise. Defaults to the field name.
aggrFuncstringNoAggregate function to apply to the field. Requires groupBy to be specified; returns an error otherwise. Supported values: SUM, COUNT, MIN, MAX.

Example

[
  {
    "name": "accountname"
  },
  {
    "name": "ownerid_fullname"
  }
]

Field types in the response

Text fields are returned as-is:

{
  "pcfTextField": "text",
  "pcfUrlField": "url",
  "pcfTelephone": "phone-number-here",
  "pcfNumber": 999
}

Lookup fields return two entries — the ID and a name entry with the primary field value of the related record:

{
  "lookup": "1234-123456-123445-2222",
  "lookupName": "name of the record"
}

Related fields are returned as requested:

{
  "lookup_pcfTextField": "text here"
}

Picklist fields return two entries — the attribute value and a name entry with the display value:

{
  "picklist": "1",
  "picklistname": "value"
}

Errors

StatusError
400 Bad RequestInvalid field: {fieldName} — one or more fields don't exist in the system.
400 Bad RequestAggregation functions require a GROUP BY clause — a field has aggrFunc but no groupBy is specified.

filter

A filter is an array of condition groups. All condition groups under the filter array are joined with AND logic between them.

conditionGroup

PropertyTypeNotes
typeAND or ORThe logical operator applied between the conditions in this group.
conditionsarray of conditionAt least one condition is required.

condition

PropertyTypeNotes
fieldNamestringThe field name to filter on. Supports related fields (e.g. ownerid_fullname).
operatorstringOne of the supported operators.
valuestring, number, boolean, array, or omittedDepends on the operator and field type.

Example

"filter": [
  {
    "type": "AND",
    "conditions": [
      {
        "fieldName": "accountname",
        "operator": "start-with",
        "value": "Y"
      }
    ]
  },
  {
    "type": "OR",
    "conditions": [
      {
        "fieldName": "ownerid",
        "operator": "eq",
        "value": "3b6b3b37-41fa-413e-bb42-f802128cc092"
      },
      {
        "fieldName": "originatingleadcode",
        "operator": "eq-in",
        "value": [4, 7]
      }
    ]
  }
]

In this example, the two condition groups are combined with AND. The first group requires accountname to start with "Y". The second group requires either a specific owner or a lead code of 4 or 7.

Errors

StatusError
400 Bad RequestInvalid field: {fieldName}
400 Bad RequestInvalid operator: {operator}
400 Bad RequestInvalid type: {type} — the condition group type must be AND or OR.
400 Bad RequestMissing property: {propertyName} — a required property (fieldName, operator, value, type, or conditions) is missing.
400 Bad Request{fieldName} expects an array as value — operators eq-in, not-in, and between require an array value.

Operators

OperatorValueExpectsDescription
Equaleqsingle valueChecks if the field equals the value.
Not equalnesingle valueChecks if the field does not equal the value.
Less thanltsingle valueChecks if the field is less than the value. For dates, returns records before the given date.
Greater thangtsingle valueChecks if the field is greater than the value. For dates, returns records after the given date.
Less or equallesingle valueChecks if the field is less than or equal to the value.
Greater or equalgesingle valueChecks if the field is greater than or equal to the value.
Starts withstart-withsingle valueChecks if the field starts with the given string (case-insensitive). Prefix the value with % to match anywhere in the field.
Not starts withnot-start-withsingle valueChecks if the field does not start with the given string (case-insensitive). Prefix the value with % to match anywhere.
Is nullis-nullno valueChecks if the field is empty. Do not provide a value.
Is not nullis-not-nullno valueChecks if the field is not empty. Do not provide a value.
Ineq-inarrayChecks if the field matches any value in the array.
Not innot-inarrayChecks if the field does not match any value in the array.
Betweenbetweenarray of 2Checks if the field is between the two values (inclusive).
Current useruseridno valueMatches records where the field equals the current user's ID. Do not provide a value.

Providing a value for operators that expect none, or a non-array value for operators that expect an array, will return a 400 error.


Relative date values

When filtering on date or datetime fields, you can use relative date values instead of fixed dates. These are supported with operators eq, ne, lt, gt, le, and ge.

ValueDescription
nowCurrent date and time
todayToday
yesterdayYesterday
tomorrowTomorrow
this-weekCurrent week
last-weekPrevious week
next-weekNext week
last-2-weeksPrevious 2 weeks
next-2-weeksNext 2 weeks
this-monthCurrent month
last-monthPrevious month
next-monthNext month
this-yearCurrent year
last-yearPrevious year
next-yearNext year
last-30-daysPrevious 30 days
next-30-daysNext 30 days
last-60-daysPrevious 60 days
next-60-daysNext 60 days
last-90-daysPrevious 90 days
next-90-daysNext 90 days
next-2-monthsNext 2 months
last-2-monthsPrevious 2 months
next-3-monthsNext 3 months
last-3-monthsPrevious 3 months
next-12-monthsNext 12 months
last-12-monthsPrevious 12 months
this-quarterlyCurrent quarter
last-quarterlyPrevious quarter
next-quarterlyNext quarter
quarterly-1Q1 (Jan–Mar)
quarterly-2Q2 (Apr–Jun)
quarterly-3Q3 (Jul–Sep)
quarterly-4Q4 (Oct–Dec)
2-days-ago2 days ago
2-days-after2 days from now

Example

{
  "fieldName": "createdon",
  "operator": "eq",
  "value": "today"
}

orderBy

An orderBy object specifies how to sort the results.

PropertyTypeRequiredNotes
namestringYesA valid field name. Supports related fields (e.g. ownerid_fullname).
orderasc or descNoDefault: asc.

Example

[
  {
    "name": "accountname",
    "order": "asc"
  },
  {
    "name": "ownerid_fullname",
    "order": "desc"
  }
]

If orderBy is empty or omitted, results are sorted by the primary key field of the object. When the query contains groupBy and no orderBy, results are sorted by the first field in groupBy.

When the query includes groupBy, all orderBy fields must also appear in the groupBy array.

Errors

StatusError
400 Bad RequestInvalid field: {fieldName}
400 Bad RequestInvalid value in property 'order' under 'orderBy': {wrongValue}
400 Bad RequestAll orderBy fields must be included in the GROUP BY clause — only when the query contains groupBy.

groupBy

A groupBy object specifies which fields to group results by. This is required when using aggregation functions (aggrFunc) in the fields array.

PropertyTypeRequiredNotes
namestringYesA valid field name. Supports related fields (e.g. ownerid_fullname).

Example

[
  {
    "name": "statuscode"
  },
  {
    "name": "ownerid_fullname"
  }
]

Rules

  • All non-aggregated fields in the fields array must also appear in groupBy.
  • All orderBy fields must also appear in groupBy.

Errors

StatusError
400 Bad RequestInvalid field: {fieldName}
400 Bad RequestAll selected fields must be included in the GROUP BY clause

Aggregation

You can apply aggregation functions to fields when using groupBy. Set the aggrFunc property on a field object.

Supported functions: SUM, COUNT, MIN, MAX.

Example

{
  "objectType": 1,
  "fields": [
    {
      "name": "createdby"
    },
    {
      "name": "revenue",
      "alias": "Total",
      "aggrFunc": "SUM"
    }
  ],
  "groupBy": [
    {
      "name": "createdby"
    }
  ]
}

The aggregated value is returned under the alias (if provided) or under the field name.


Pagination

PropertyDefaultRange
pageSize251–500
pageNumber1Positive integer

The response includes an isLastPage boolean. When false, increment pageNumber to fetch the next page.

Errors

StatusError
400 Bad RequestInvalid pageSize. Range is 1 to 500
400 Bad RequestInvalid page number

Full example

Request

POST https://api.fireberry.com/api/v3/query HTTP/1.1
tokenid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
Content-Type: application/json

{
  "objectType": 1,
  "fields": [
    { "name": "accountname" },
    { "name": "telephone1" },
    { "name": "statuscode" }
  ],
  "filter": [
    {
      "type": "AND",
      "conditions": [
        {
          "fieldName": "accountname",
          "operator": "start-with",
          "value": "Bob"
        },
        {
          "fieldName": "statuscode",
          "operator": "eq-in",
          "value": [1, 2]
        }
      ]
    }
  ],
  "orderBy": [
    { "name": "accountname", "order": "asc" }
  ],
  "pageSize": 25,
  "pageNumber": 1
}

Response

{
  "data": [
    {
      "_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "accountname": "Bob Davis",
      "telephone1": "0501234567",
      "statuscode": 1
    },
    {
      "_id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "accountname": "Bob Johnson",
      "telephone1": "0509876543",
      "statuscode": 2
    }
  ],
  "success": true,
  "message": "",
  "pageNumber": 1,
  "pageSize": 25,
  "isLastPage": true
}