When you use the ProjectManager API, you can search for your information using the query language OData. All data types within ProjectManager can be retrieved using OData queries.
So let’s break this down - what is an OData query? It is a type of query that allows you to:
$filter parameter.$top and $skip.$orderby.$expand.$select.Let’s walk through the basics for an OData query.
Let’s begin by dMany users want to begin by fetching a specific subset of tasks. In this case, we’ll write a query to fetch a list of tasks that have specific tags. Our developer wants to retrieve a list of tasks that have been tagged with the customer-issue tag. But, we only want to find tasks from a specific swimlane. How do we do this?
tags collection.any method since any particular task could have lots of tags.customer-issue.tags/any(o: o/name eq 'customer-issue').Next, we want to identify the swimlane. The swimlane is stored in the field name within the status object, so to query it we use the statement status/name followed by a filter such as equals. We want to look for the swimlane “Waiting”.
Combining these two queries together, we get this query:
Whenever you want to find a specific record in the ProjectManager system, you can use an OData filter statement to search. Microsoft provides a nice tutorial page on learning OData filter expressions which goes into more detail, but let’s summarize it here.
$filter={field-name} eq {value} statement, like $filter=shortCode eq MyNewProject$filter={field-name} gt {date} statement, like $filter=createDate gt 2023-03-01$filter=contains({field-name}, '{substring}') statement, like $filter=contains(notes, 'test').You can combine multiple comparisons using parenthesis and AND / OR clauses. Some examples:
(projectId eq 8aff412f-f072-479a-837e-eb0d96c6904a AND percentComplete eq 100)(contains(name, 'wash') AND percentComplete eq 0)When specifying values in your query, keep in mind these things:
count eq 7name eq 'Bob Smith'projectId eq 8aff412f-f072-479a-837e-eb0d96c6904acreateDate gt 2023-01-01The standard for OData pagination uses the concept of top and skip. Here’s how it works.
The server begins to produce a list of all records matching your $filter statement in the order specified by the $orderby parameter.
The server will omit the number of records specified by the $skip parameter, if it is present.
If there are still more records remaining after the $skip parameter has been exhausted, the server will begin delivering records up until the $top value is reached.
This allows you to paginate records easily. If you want to retrieve the top 50 records in a table, you specify $top=50. To retrieve the second page of results, specify $skip=50 and $top=50.
Some OData query endpoints allow you to fetch additional data using the $expand parameter. The documentation for the API will explain what options are available and how to use them on each endpoint.