This is a staging build of the docs. Do not share the link externally.
Skip to main content

Querying

Basics and examples of querying in Codat's APIs

The Codat API uses a simple, flexible query language to allow you to filter response data.

Use URL encoding

Include a URL encoded query parameter with your request to filter data returned from the API.

The below query functionality will only work when searching for company data (e.g. invoices, customers, etc), they will not work on settings or metadata endpoints such as listing integrations, companies or data connections.

Query format

  • The query takes the form of propertyName=value.
  • You can also include comparison operators, such as greater than, less than or equal to. The following table shows comparison operators that are supported for numeric, date, and string data types.
OperatorNameEncodedNumberStringDate
=Equals%3d
!=Not equals%21%3d
~Contains%7E
>Greater than%3e
<Less than%3c
>=Greater than or equal to%3e%3d
<=Less than or equal to%3c%3d
&&AND%26%26---
||OR%7C%7C---
{, }Logical separator%7B, %7D---
  • Separate multiple query clauses with ampersands (&&) for AND queries or pipes (||) for OR queries.
  • Access sub-properties by separating them from the property with a dot (see Invoices to a particular customer example below). This is only applicable to objects within our data endpoints. We do not support querying inside arrays.
Combining queries

To combine AND and OR queries, use curly braces ({ and }). For example:

query={totalAmount > 100 || totalAmount < 50} && status != paid

Query length limits

The total length of your query should be under 2048 characters in order to be valid. If your query is longer, the API will return an error message.

Querying on null fields

We do not currently support querying on null fields.

Getting all vs one item

Our GET /{dataType} endpoints typically return an array of items of that given data type. If you want to retrieve just a single data type by an ID, you can use a query. For example:

query=id%253D81be41e9-5c2c-4064-829c-bca43b5e6f59.

Example queries

Invoices with amounts outstanding

Query: amountDue > 0

GET /companies/{companyId}/data/invoices?query=amountDue%3e0

Invoices in GBP

Query: currency = GBP

GET /companies/{companyId}/data/invoices?query=currency%3dGBP

Invoices for a specific customer

Query: customerRef.id = 61

GET /companies/{companyId}/data/invoices?query=customerRef.id%3d61

Outstanding Invoices worth less than 1000

Query: amountDue > 0 && totalAmount < 1000

GET /companies/{companyId}/data/invoices?query=amountDue%3e0%26%26totalAmount%3c1000

Invoices that are due after a certain date

e.g. "2021-01-28" (YYYY-MM-DD format)

Query: dueDate > 2021-01-28

GET /companies/{companyId}/data/invoices?query=dueDate%3E2021-01-28

Invoices deleted in the source platform

Query: metadata.isDeleted!=true

Codat identifies records that have been deleted in the source accounting platform between successive data syncs using the isDeleted flag. You may need to exclude these records from the results.

GET /companies/{companyId}/data/invoices?query=metadata.isDeleted%21%3dtrue

Companies with "Pending" status connections

Query: dataConnections.status=PendingAuth

Note: the page size value is obligatory for querying.

using CodatPlatform;
using CodatPlatform.Models.Shared;
using CodatPlatform.Models.Operations;

var sdk = new CodatPlatformSDK(
security: new Security() {
AuthHeader = "Basic BASE_64_ENCODED(API_KEY)",
}
);

var res = await sdk.Companies.ListAsync(new ListCompaniesRequest() {
Query = "dataConnections.status=PendingAuth",
});

// handle response

Queries that won't work

Although you can query properties of objects, you can't query arrays.

✅ Objects: Invoices > customerRef.id

GET /invoices?page=1&pageSize=100&query=customerRef.id%3Def6f54c1-eb45-4956-b8cd-1be82ad665f2

❌ Arrays: Invoices > lineItems

GET /invoices?page=1&pageSize=100&query=lineItems.unitAmount%3D700


Was this page useful?
❤️
👍
🤔
👎
😭