Queries (v3)
Learn how to use the v3 query endpoint to search, filter, sort, aggregate, and paginate records using a structured JSON body.
Please noteThis 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
| Property | Type | Required | Default | Notes |
|---|---|---|---|---|
objectType | integer | Yes | The numeric object type code to query. | |
fields | array of field | Yes | At least one field must be specified. | |
filter | array of conditionGroup | No | Filter conditions to apply. | |
orderBy | array of orderBy | No | Fields to sort results by. | |
groupBy | array of groupBy | No | Fields to group results by. Required when using aggregation functions. | |
pageNumber | integer | No | 1 | Must be a positive integer. |
pageSize | integer | No | 25 | Valid range: 1–500. |
Query modesThe query operates in two modes depending on whether
groupByis provided:
- Simple mode (no
groupBy): returns individual records.aggrFuncandaliason fields have no effect.- Aggregation mode (with
groupBy): returns grouped results. Fields must either appear ingroupByor have anaggrFunc. AllorderByfields must also appear ingroupBy.
objectType
This property must be a valid object type code that exists in your system.
| Status | Error |
|---|---|
| 400 Bad Request | Invalid objectType: {objectType} |
| 403 Forbidden | User has no read permissions |
fields
A field object describes which fields to include in the response, and optionally how to aggregate them.
| Property | Type | Required | Notes |
|---|---|---|---|
name | string | Yes | A 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). |
alias | string | No | An alias for the aggregated field in the result set. Only used when aggrFunc is specified; ignored otherwise. Defaults to the field name. |
aggrFunc | string | No | Aggregate 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
| Status | Error |
|---|---|
| 400 Bad Request | Invalid field: {fieldName} — one or more fields don't exist in the system. |
| 400 Bad Request | Aggregation 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
| Property | Type | Notes |
|---|---|---|
type | AND or OR | The logical operator applied between the conditions in this group. |
conditions | array of condition | At least one condition is required. |
condition
| Property | Type | Notes |
|---|---|---|
fieldName | string | The field name to filter on. Supports related fields (e.g. ownerid_fullname). |
operator | string | One of the supported operators. |
value | string, number, boolean, array, or omitted | Depends 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
| Status | Error |
|---|---|
| 400 Bad Request | Invalid field: {fieldName} |
| 400 Bad Request | Invalid operator: {operator} |
| 400 Bad Request | Invalid type: {type} — the condition group type must be AND or OR. |
| 400 Bad Request | Missing 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
| Operator | Value | Expects | Description |
|---|---|---|---|
| Equal | eq | single value | Checks if the field equals the value. |
| Not equal | ne | single value | Checks if the field does not equal the value. |
| Less than | lt | single value | Checks if the field is less than the value. For dates, returns records before the given date. |
| Greater than | gt | single value | Checks if the field is greater than the value. For dates, returns records after the given date. |
| Less or equal | le | single value | Checks if the field is less than or equal to the value. |
| Greater or equal | ge | single value | Checks if the field is greater than or equal to the value. |
| Starts with | start-with | single value | Checks if the field starts with the given string (case-insensitive). Prefix the value with % to match anywhere in the field. |
| Not starts with | not-start-with | single value | Checks if the field does not start with the given string (case-insensitive). Prefix the value with % to match anywhere. |
| Is null | is-null | no value | Checks if the field is empty. Do not provide a value. |
| Is not null | is-not-null | no value | Checks if the field is not empty. Do not provide a value. |
| In | eq-in | array | Checks if the field matches any value in the array. |
| Not in | not-in | array | Checks if the field does not match any value in the array. |
| Between | between | array of 2 | Checks if the field is between the two values (inclusive). |
| Current user | userid | no value | Matches 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.
| Value | Description |
|---|---|
now | Current date and time |
today | Today |
yesterday | Yesterday |
tomorrow | Tomorrow |
this-week | Current week |
last-week | Previous week |
next-week | Next week |
last-2-weeks | Previous 2 weeks |
next-2-weeks | Next 2 weeks |
this-month | Current month |
last-month | Previous month |
next-month | Next month |
this-year | Current year |
last-year | Previous year |
next-year | Next year |
last-30-days | Previous 30 days |
next-30-days | Next 30 days |
last-60-days | Previous 60 days |
next-60-days | Next 60 days |
last-90-days | Previous 90 days |
next-90-days | Next 90 days |
next-2-months | Next 2 months |
last-2-months | Previous 2 months |
next-3-months | Next 3 months |
last-3-months | Previous 3 months |
next-12-months | Next 12 months |
last-12-months | Previous 12 months |
this-quarterly | Current quarter |
last-quarterly | Previous quarter |
next-quarterly | Next quarter |
quarterly-1 | Q1 (Jan–Mar) |
quarterly-2 | Q2 (Apr–Jun) |
quarterly-3 | Q3 (Jul–Sep) |
quarterly-4 | Q4 (Oct–Dec) |
2-days-ago | 2 days ago |
2-days-after | 2 days from now |
Example
{
"fieldName": "createdon",
"operator": "eq",
"value": "today"
}orderBy
An orderBy object specifies how to sort the results.
| Property | Type | Required | Notes |
|---|---|---|---|
name | string | Yes | A valid field name. Supports related fields (e.g. ownerid_fullname). |
order | asc or desc | No | Default: 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
| Status | Error |
|---|---|
| 400 Bad Request | Invalid field: {fieldName} |
| 400 Bad Request | Invalid value in property 'order' under 'orderBy': {wrongValue} |
| 400 Bad Request | All 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.
| Property | Type | Required | Notes |
|---|---|---|---|
name | string | Yes | A valid field name. Supports related fields (e.g. ownerid_fullname). |
Example
[
{
"name": "statuscode"
},
{
"name": "ownerid_fullname"
}
]Rules
- All non-aggregated fields in the
fieldsarray must also appear ingroupBy. - All
orderByfields must also appear ingroupBy.
Errors
| Status | Error |
|---|---|
| 400 Bad Request | Invalid field: {fieldName} |
| 400 Bad Request | All 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
| Property | Default | Range |
|---|---|---|
pageSize | 25 | 1–500 |
pageNumber | 1 | Positive integer |
The response includes an isLastPage boolean. When false, increment pageNumber to fetch the next page.
Errors
| Status | Error |
|---|---|
| 400 Bad Request | Invalid pageSize. Range is 1 to 500 |
| 400 Bad Request | Invalid 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
}Updated about 9 hours ago
