Making basic query calls to the REST API

This article describes foundational concepts for querying resource data in Autotask by making GET and POST requests to the REST API.

We recommend reading this article after you have familiarized yourself with the key principles discussed in our Introduction to REST API calls article. For advanced query syntax, refer to Advanced query features of the REST API.

To help you learn how to construct requests to the Autotask REST API, Datto provides a customizable REST API request collection for use with Postman. For more information, refer to Sample requests.

Overview

You can query the REST API by entity ID or by using filter expressions. Querying by entity ID will return the single entity result that corresponds with the ID value. Using filters enables you to query just the data that you need.

The REST API supports a variety of filter operators. You can also group filter expressions by using AND & OR expressions.

BEFORE YOU BEGIN  Examples in this article may use the webservices[n].autotask.net placeholder. In such instances, substitute [n] for the zone of your user, as described in Autotask API zones and WSDL versionsFind your zone's API URL for the REST API or Autotask API zones and WSDL versionsFind your zone's WSDL file URL for SOAP API version 1.6.

Index

Before you begin

There are several key concepts to keep in mind when working with query calls.

Anatomy of a query response

All queries to the Autotask REST API share certain common elements. Click each description's name to view demonstration code and an explanation of the elements shown.

GET by ID

In this basic query, the call to the API passes the ID of an object and returns a single entity result. Click each description's name to view demonstration code and an explanation of the operator shown.

Filter operators

Most calls to the API will require the use of one or more filter operators to indicate the type of query you'd like the API to perform. The table below lists the available operators and their definitions.

Operator Definition
eq Requires that the field value match the exact criteria provided
noteq Requires that the field value be anything other than the criteria provided
gt/gte Requires that the field value be greater than or equal to the criteria provided
lt/lte Requires that the field value be less than or equal to the criteria provided
beginsWith Requires that the field value begin with the defined criteria
endsWith Requires that the field value end with the defined criteria
contains Allows for the string provided as criteria to match any resource that contains the string in its value
exist Enter exist to query for fields in which the data you specify is not null.
notExist

Enter notExist to query for fields in which the specified data is null.

in With this value specified, the query will return only the values in the list array that match the field value you specify.
notIn With this value specified, the query will only return the values in the list array that do not match the field value you specify.

GET with filter

The syntax for most GET filter expressions follows the convention shown below. Click the description's name to view demonstration code and an explanation of the syntax shown.

Comparison operators

In a comparison operator, the query compares the value against the specified operator. The below examples demonstrate simple comparison operators. Click each description's name to view demonstration code and an explanation of the operator shown.

Non-comparison operator

A non-comparison operator queries for the specified criteria without comparing it against any operators other than exist or notExist. The below examples demonstrate simple non-comparison operators. We recommend using POST to execute calls for complicated queries that have long filter expressions.

Click each of the headers below to view example syntax.

List operator

When working with lists, the operator may be either in or notIn. With in specified, the query will return only the values in the list array that match the specified field value. For not in, the query will only return the values in the list array that do not match the field. The below examples demonstrate simple list operators. While you may use GET or POST with these operators, we recommend using POST to execute complicated queries that have long filter expressions.

Click each description's name to view its details.

UDF comparison operator

You can include user-defined fields (UDFs) in your query. By specifying a udf value of true, you indicate to the API that the field you provide in your query is user-defined. The udf expression must always follow the field expression in the API call.

IMPORTANT  You can only query by one user-defined field at a time.

If you attempt to call a UDF without including the udf value in your query, the call may result in an error state. It is not necessary to include the udf value if you are not calling a user-defined field.

Grouping syntax for OR & AND

You can use grouping to allow for combinations of AND & OR operators within nested groups. You can perform these operations with GET or POST requests. Click each description's name to view demonstration code and an explanation of the operator shown.

Querying with POST

You can use POST to pass an advanced query via URL. In the base POST request, you call the query endpoint of the desired entity. In the body of the request, you specify the query parameters. Click the description's name to view demonstration code and an explanation of the operator shown.

Additional resources