Completed sections in Asana API - asana

Since sections in Asana are usual tasks, they can be completed. Asana API provides an ability to receive sections of a project https://asana.com/developers/api-reference/projects#sections, but unfortunately, it returns all sections including the completed one. Are there any other ways to receive only active sections or at least the completion flag for sections?

You can query for incomplete tasks in a project by using completed_since=now when querying for tasks. However, there is no way to scope that query to only return sections within the project.
However, when querying for a list of objects the Asana API will return a compact representation of those objects, this is what you get when calling /sections on a project. In order to return specific fields on the object you can use field selectors
To get the completed field simply add opt_fields=completed as a query parameter like this:
https://app.asana.com/api/1.0/projects/<PROJECT_ID>/sections?opt_fields=completed

Related

How do we use select inside an expanded collection on Microsoft Graph?

Following query in MS Graph Explorer displays signed-in user's profile and its manager Diego Siciliani
https://graph.microsoft.com/v1.0/me?$expand=manager
But you may notice in the response it is returning tons of attributes of manager object, as well. Some of these attributes are objects (such as assignedPlans) themselves and have their own attributes, as well.
Question: How can we filter the above query so it returns user profile (that it is already doing) along with ONLY the following attirbute value the user's manager: "displayName": "Diego Siciliani"
Remark: Following query returns the error shown below: https://graph.microsoft.com/v1.0/me?$expand=manager($select=displayName)
Invalid $select properties
Please use the below query to get user and his manager details
https://graph.microsoft.com/v1.0/users/userid?$expand=manager($levels=max;$select=id,displayName)&$select=id,displayName&$count=true
ConsistencyLevel eventual
Update https://graph.microsoft.com/v1.0/me?$expand=manager($levels=max;$select=displayName)&$count=true
It is known issue from Microsoft that nested $select combined with $expand doesn't work (i.e. $expand=some_path($select=some_field) does not work with Microsoft Graph API).
See: https://learn.microsoft.com/en-us/graph/known-issues#query-parameter-limitations
$expand:
No support for nextLink
No support for more than 1 level of expand
No support with extra parameters ($filter, $select)
I wish they would implement it because right now we either have to pull a lot of extra data (e.g. for managers), or we have to make a lot of requests per user to retrieve just the field we want.
There's a solution that deal with batch requesting but it requires a json solution: https://learn.microsoft.com/en-us/graph/json-batching?view=graph-rest-1.0

Microsoft Graph api - Missing 'none' (or not any) functionality for $filter

I'm trying to retrieve any message that I haven't specifically categorized but there isn't a none filter option for Microsoft Graph. I tried to invert the any filter by using the following call:
/v1.0/me/messages?$filter=categories/any(c:c ne 'MyCategory')
However, this will still return items containing 'MyCategory'. Is there another method by which I can retrieve items that don't have that category set on them? (Returning items with no category set at all is not exclusive enough).
I had contemplated using custom extensions, however, the filter for extensions also lacks a none option.
try this
im not sure is this is your request
https://graph.microsoft.com/v1.0/me/messages/?$select=categories
There really isn't a good way to do negative comparisons like this within the API itself.
The reason any doesn't work is that your query translates to "include the message if any of it's categories are not 'MyCategory'". That would include messages with no categories (i.e. null) as well as message with any other category (i.e. a message with both MyCategory and Blue Category would match the filter).
Your best bet is using Open Extensions. These allow you to add application-specific data to Graph resources that you can filter against.

Select specific fields from users and expanded manager

I want to get manager relation for all users and this can easily be done with https://graph.microsoft.com/beta/users?expand=manager.
But I get all data on all users and all data for each manager, which is way too much! I want to limit my result set to only return id and displayName for user and only id on the manager relation.
https://graph.microsoft.com/beta/users?select=id,displayName&expand=manager(select=id)
This is not working and I get this error:
Term 'manager($select=id)' is not valid in a $select or $expand expression.
Any help is much appreciated.
Sad to say, I was looking for this as well - it seems that this is not supported:
https://developer.microsoft.com/en-us/graph/docs/concepts/query_parameters#expand-parameter
Not all resources or relationships support using $select on expanded items.
I think this means you cant use select on manager expand.
I would take it further even and say you cannot use select on the users query itself, since there is no way to include the expanded "manager" in the select, even with all its properties. Once you set a select statement your expanded manager property will be gone.
There are two choices at this point:
get the users without their manager, then create batch requests of 20 at a time to get the users managers (id only)
give up on trying to be efficient, and just get all users with their managers with all their properties. This would bloat your requests but you will get away with fewer requests.
I think depending on how much data you are planning to get (number of users, properties you need) you should choose the best way forward for you.
Here is graph API documentation that shows how to expand the entire management chain and return selected fields. Slight caveat that it works on the documentation page but it doesn't return the expected results at https://developer.microsoft.com/en-us/graph/graph-explorer.
https://graph.microsoft.com/v1.0/me?$expand=manager($levels=max;$select=id,displayName)&$select=id,displayName&$count=true
Link to graph API User List Manager:
https://learn.microsoft.com/en-us/graph/api/user-list-manager?view=graph-rest-1.0&tabs=http#code-try-8

How to prepare array by making two API calls

I'm making an "API" call for getting a list of "MyMusic" album. It returns array of music ids and those ids are linked with another table. So in order to get music details like name etc. I need to make separate "API" calls with id.
What is the recommended way to make "API" calls to fill my array with music details.
Depends on if the API can return multiple id's. Can you send a JSON-array to the API and get an array in return? If not, it looks like you have to send the id's one at a time.
If you don't for some reason NEED to use the REST api (which it seems you are doing now), then in your first query use includeKey on the field that contains the IDs. If this field is a Pointer to another table, this will make sure the full objects are returned in the first query instead of just the pointers.

Difference between Deep Insert and $batch OData

Can any one tell me the difference between usage of Deep Insert and $batch - ChangeSet in the context of OData ? I have a scenario that requires creation of a Sales Order Header and Sales Order Items together.
I can either user Deep Insert (BTW is this standard OData spec ?) or
I can use a $batch (this is standard OData spec) call with these two entities specified as a part of the same ChangeSet, which would ensure that they get saved together as a part of a single LUW.
What are the pros / cons of using either of these approaches ? Any experiences ?
Cheers
Deep Insert is part of the OData specification, see http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793718.
Deep Insert allows creating a tree of related entities in one request. It is insert only.
$batch allows grouping arbitrary requests into one request, and arbitrary modifying operations into LUWs (called change sets).
For insert-only cases Deep Insert is easier: you just POST the same format that you would GET with $expand.
Deep insert or deep update is not currently defined and supported by OData spec. However there are such feature requests, like this: https://data.uservoice.com/forums/72027-wcf-data-services-feature-suggestions/suggestions/4416931-odata-deep-update-request-support
If you decided to use a batch, then you have to do the next set of commands in your batch:
PUT SalesOrderItem
...
PUT SalesOrderItem
PUT SalesOrderHeader
PUT SalesOrderHeader/links$/SalesOrderItem
...
PUT SalesOrderHeader/links$/SalesOrderItem
See also here: How do I update an OData entity and modify its navigation properties in one request?
In our ASP.NET project we decided to go with CQRS pattern and use OData for Query requests and Web API for Commands. Talking in terms of your case we created Web API Controller with action CreateSalesOrder with parameter of class SalesOrderHeaderDto that contains array of SalesOrderItemDtos. Having the data on server you can easily develop insert the whole Order Sale in one transaction with its Order Items. Also there is just two command to be sent on server - ~/api/CreateSalesORder and ~/odata/SalesOrder with include=Items and filter by something... for example first command can return an Id of the Order...
Deep insert gives one operation that will insert all the items as one operation.
The same thing isn't possible in a $batch.
This is not automatic in a batch :
they get saved together as a part of a single LUW
The $batch needs to be in a single change set to expect atomicity.
According to OData 4.0 11.7.4 Responding to a Batch Request:
All operations in a change set represent a single change unit so a service MUST successfully process and apply all the requests in the change set or else apply none of them. It is up to the service implementation to define rollback semantics to undo any requests within a change set that may have been applied before another request in that same change set failed and thereby apply this all-or-nothing requirement. The service MAY execute the requests within a change set in any order and MAY return the responses to the individual requests in any order. The service MUST include the Content-ID header in each response with the same value that the client specified in the corresponding request, so clients can correlate requests and responses.
However, a single changeset is unordered. Given you are doing a deep insert, there is some realtionship between the entities, and given you are doing an insert, in either a contained navigation or a $ref navigation you can't perform both inserts or both inserts and the PUT / POST $ref in an unordered fashion.
A change set is an atomic unit of work consisting of an unordered group of one or more Data Modification requests or Action invocation requests.

Resources