Retrieve and filter collections
When you retrieve a collection with the REST API, you can shape the response using query parameters. You can restrict which fields are returned, filter the entities, sort them, page through large result sets, and group them with an aggregate.
Restricting fields
Use the fields parameter to specify which fields to return, as a comma-separated list. Requesting only the fields you need reduces the size of the response.
GET /defects?fields=id,name,severity,phase
Note the following:
-
The
idandtypefields are always returned, whether or not you request them. -
When you do not specify
fields, the identifying fields are returned:id,workspace_id,type,subtype, andlogical_name. -
Request other fields explicitly to retrieve them. For the fields available on an entity, see Retrieve metadata.
For performance optimization, some fields are not included unless requested explicitly. For example, comments are not returned by default when retrieving entities.
GET /defects?fields=comments
Expand reference fields
Relations between entities are exposed as reference fields identified by a relation alias, such as detected_in_release. Request these fields with fields, expand them to select data from the related entity, or filter by related-entity fields using cross-filtering.
Note: To change a relation, update its reference field with a PUT request. For details, see PUT: Update an instance.
You can expand a reference field to return specific fields of the referenced entity, by listing those fields in braces after the field name. Expansion is recursive up to three levels, and is supported when reading a collection.
GET /defects?fields=id,name,release{id,name,start_date,end_date}
The following example expands two levels — the team, and the team lead within it:
GET /defects?fields=id,name,team{id,name,team_lead{id,full_name,email}}
Additional default fields of an expanded reference are returned together with the fields you request. Only selectable fields that are public or tech preview are returned.
Filtering
Use the query parameter to return only the entities that match a condition. The whole query is enclosed in double quotation marks, and is built from one or more query phrases. Each phrase compares a field to a value with a comparison operator:
GET /defects?query="name = 'Login fails'"
Comparison operators
Each operator has two equivalent spellings — a symbol and a keyword. You can use either; the server treats them the same.
| Symbol | Keyword | Meaning |
|---|---|---|
=
|
EQ
|
Equal to |
<
|
LT
|
Less than |
>
|
GT
|
Greater than |
<=
|
LE
|
Less than or equal to |
>=
|
GE
|
Greater than or equal to |
| — | IN
|
Matches any value in a comma-separated list |
| — | BTW
|
Within an inclusive range of two values |
Which operators are valid depends on the field's data type:
| Data type | Supported operators |
|---|---|
| Integer | EQ, LT, GT, LE, GE, IN, BTW |
| Date/time | EQ, LT, GT, LE, GE, IN, BTW |
| String | EQ, IN |
| Boolean | EQ
|
| Reference | EQ, IN |
| Memo | Not supported — memo fields cannot be filtered. |
Values
-
Strings. Wrap a string value in single quotation marks (
'High') or, equivalently, in carets (^High^). The two forms are interchangeable.Note:
-
String comparison is not trimmed, so leading or trailing spaces are significant.
-
List (enum) fields such as
severity, and user fields such asowner, are reference entities and cannot be filtered by a plain string value — use the cross-filter syntax instead:severity = {name = 'High'}. See Cross-filtering on referenced entities.
-
-
Numbers and Booleans. Write them unquoted, as in
story_points = 5orhas_attachments = true. -
Date/time. Use an ISO-8601 UTC timestamp wrapped like a string, and include the full date and time (date-only is not accepted):
creation_time LT '2015-02-25T16:42:11Z'. Offsets such as2018-03-12T16:42:11%2B01:00(URL-encoded+01:00) are also accepted. -
Wildcard. Use
*within a string value to match any sequence of characters, as inname = 'release*'. -
No value. Match entities that have no value in a field by comparing it to
null. For a simple field, useowner = null. For a reference field, wrap it in braces:detected_in_release = {null}. For a nullable string field,nulldoes not match an empty string.
Contextual value tokens
An IN list can include tokens that the server resolves for the current request:
-
[current_user]— the user calling the API. -
[current_release]— the release set as the default in the settings.
GET /defects?query="owner IN [current_user], 1001, 1002"
Ranges
Use BTW with two values separated by ... (with a space before the dots) to match an inclusive range:
GET /defects?query="id BTW 12 ...16"
Combining conditions
Combine phrases with logical operators. In order of precedence (highest first): parentheses ( ), then negation !, then AND ;, then OR ||.
| Operator | Meaning |
|---|---|
;
|
And |
||
|
Or |
!
|
Not (reverses the phrase that follows) |
GET /defects?query="name = 'Login*';story_points > 3"
Use parentheses to control evaluation order, as in "(name = 'Login*' || name = 'Logout*');story_points > 3".
Escaping special characters
If a string value contains a character that has meaning in the query syntax, escape it with a backslash. The URL-encoded form is shown in parentheses.
| Character | Escaped form |
|---|---|
"
|
\" (%5C%22) |
^
|
\^ (%5C%5E) |
\
|
\\ (%5C%5C) |
'
|
\q (%5Cq) |
<
|
\l (%5Cl) |
>
|
\g (%5Cg) |
{
|
\{ (%5C%7B) |
(
|
\( (%5C() |
)
|
\) (%5C)) |
[
|
\[ (%5Cb) |
?
|
\? (%5C%3F) |
*
|
Cannot be used as a literal — filtering by * is not supported. |
Cross-filtering on referenced entities
You can filter a collection by the fields of a referenced entity by wrapping a nested query in braces after a reference field. For example, to return defects detected in the release with ID 1004:
GET /defects?query="detected_in_release = {id = 1004}"
Cross-filters can be nested without limit. To return defects detected in a specific sprint of a specific release:
GET /defects?query="detected_in_release = {sprints = {id = 1006}}"
Filtering on list fields
List (enum) fields, such as severity and phase, are referenced entities. Filter them either by logical name or by label name. Filtering by logical name is language-independent; filtering by label name is supported only in English.
GET /work_items?query="subtype = 'defect';severity = {logical_name = 'list_node.severity.high'}"
GET /work_items?query="subtype = 'defect';severity = {name = 'High'}"
Wildcards work here too: severity = {name = '*high'} matches High, Very High, and so on.
To look up the logical names or label names available for a list field, query the list_nodes collection:
GET /list_nodes?query="logical_name = '*high'" GET /list_nodes?query="name = '*high'"
Note: Do not filter a list field by its string value directly — this does not work. You must use the cross-filter syntax with braces: severity = {name = 'High'}, not severity = 'High'.
Filtering on user fields
When cross-filtering on a user-type field, such as owner or author, you can reference only the id field:
GET /defects?query="owner = {id = 1003}"
Note: Referencing any field other than id on a user-type field does not work, for example owner = {name = 'Ann*'} is not supported.
Filtering by subtype
For an aggregated entity type, the subtypes parameter restricts the request to specific subtypes, given as a comma-separated list. For example, a work item is an aggregated type whose subtypes include defect and story:
GET /work_items?subtypes=defect,story
You can achieve the same filtering within query by matching the subtype field directly. See Filtering.
Query across workspaces
You can query data from multiple workspaces within a shared space using the cross_workspace parameter. Use the * wildcard to include all workspaces assigned to the current user, or provide a comma-separated list of workspace IDs.
GET /defects?fields=id&cross_workspace=* GET /defects?fields=id&cross_workspace=1001,1002
To restrict the query to workspaces that match certain attributes — for example, only active workspaces — add the cross_workspace_query parameter alongside cross_workspace:
GET /defects?fields=id&cross_workspace=*&cross_workspace_query=(active=1)
Text search
Use the text_search parameter to match entities by keyword, or by similarity to another entity, instead of an exact query condition.
For details, see Text search.
Grouping and aggregation
Rather than returning individual entities, a collection can return its entities grouped by a field, with an aggregate calculated for each group. Grouping is requested through the groups sub-collection of an entity collection, not the collection itself:
GET /work_items/groups?group_by=phase
Two parameters control the result:
-
group_by. The field to group by. To group by a field of a referenced entity, name the sub-field in braces, as ingroup_by=release{agile_type}. -
group_data. An aggregate to compute for each group, as a function of a field:sum(<field>),count(<field>), oravg(<field>).
GET /work_items/groups?group_by=phase&group_data=count(id)
Note: The groups sub-collection groups by a single field. Reporting endpoints support their own grouping, over more than one field.
Numeric and logical identifiers
For entities that have a logical name, the server can return the logical name in place of the numeric ID. Set use_numeric_id=true to suppress that conversion and keep the raw numeric id in the response.
GET /phases?use_numeric_id=true
Sorting
Use the order_by parameter to sort the results by one or more fields. By default, sorting is ascending. To sort a field in descending order, prefix its name with a minus sign (-).
GET /defects?order_by=-severity,name
Note:
-
Sorting is case-insensitive, so the values
A B C a b csort asA a B b C c. -
Most collections are ordered by name by default. For best performance on large collections, sort by
id.
Paging
Large result sets are returned one page at a time. Use the following parameters to control paging:
To paginate, use the limit and offset query parameters. On large collections, retrieving later pages can degrade performance, so reduce load by combining paging with filtering and by requesting only the fields you need.
-
offset. The index of the first entity to return, starting from0. -
limit. The maximum number of entities to return in the page.
GET /defects?offset=0&limit=100
Note the following:
-
offsetdefaults to0when omitted. -
limitmust be greater than0. A value below1, or above the maximum page size, is rejected with an error. When omitted, a server default applies. -
Set
limit=maxto request the server's maximum page size.
The total_count property in the response tells you how many entities match the request in total, so you can determine how many pages to retrieve.
Combining parameters
You can combine these parameters in a single request. For example, to return the ID and name of the first 50 high-severity defects, sorted by name:
GET /defects?fields=id,name&query="severity = {name = 'High'}"&order_by=name&offset=0&limit=50

