Asana API - how to get incomplete tasks only? - asana

How do I get a list of tasks from a project that are incomplete? I tried to add ?completed=false and ?completed=0 at the end of the tasks URL:
https://app.asana.com/api/1.0/projects/[project id]/tasks?completed=false
... doesn't seem to work. Whether its set to true or false, it is always returning the same tasks. I've spot checked to make sure there are completed tasks in there.
background info: I'm only trying to do this so that I don't get the entire list of tasks all the time. I need the entire list of tasks because right now as I understand it there is no way to get the section a task is in.

Under "Querying for Tasks" in the Developer Documentation you'll find the parameters you can pass to select different tasks. We don't support generalized queries (like completed=false) but we do have e.g. completed_since, which returns all "incomplete or completed since X" tasks. So, if you only want incomplete tasks, you can pass completed_since=now (since no completed tasks have been completed since the current time, it will only return incomplete tasks). It's not exactly intuitive, but it works :-)

Related

Power Automate - How to create Azure DevOps work items only once when the trigger is a work item update?

Context
I want to create a Power-Automate flow that automatically creates a sub-task in Azure DevOps when the Effort of a PBI is set.
When the Effort field goes from blank to a positive value, the task should be added (using the newly set Effort value as the task's Original Estimate and Remaining Work).
I managed to create a flow that does that using When a work item is update trigger.
Problem
The flow runs too often (whenever the work item changes, as long as the Effort is > 0).
Question
What would be the best way to ensure this flow runs only once per PBI?
Thoughts
Perhaps check for the presence of child tasks?
Perhaps set a hidden property when adding the task the first time and check that property afterwards?
You could add a trigger condition to the settings of your trigger action. Use the following expression:
#greater(triggerOutputs()?['body/fields/Microsoft_VSTS_Scheduling_Effort'], 0)
Add a Send an HTTP request action directly after the trigger. Use the following URI:
YourProjectName/_apis/wit/workItems/#{triggerOutputs()?['body/id']}/updates?api-version=6.0
Add a Filter Array. Use this expression for the From
body('Send_an_HTTP_request_to_Azure_DevOps')['value']
In the where of the Filter Array use the following expression which you add via the advanced mode:
#greater(length(string(item()?['fields']?['Microsoft.VSTS.Scheduling.Effort']?['newValue'])), 0)
In a condition check if the Filter Array returns no results. If it does, the value of Effort has not been changed in the past and you can safely create your new task
length(body('Filter_array'))
is equal to 1

Integromat Scenario: One-shot module after iterating through a loop

I have created a scenario where I iterate through multiple modules with an array of data. This works fine.
After this completes, I want to run a module once before the scenario completes.
How do I add a module that won't get called in the loop?
There are few ways to achieve this,
Use Router to Create a new Route that will be triggered after the
first route is complete
Trigger new Scenario via Webhooks after you are done with the
scenario
If you are working with array, then using Array Aggregator or other
Aggregators will allow you to first complete the iteration and then
trigger the module you want to use
I am not sure exactly what you want to do after the iteration is complete, but setting the scenarios as displayed in the screenshot below should help you get started on this,
Using Router
For this you can create a router, the upper hand of the router is always executed first, so the iterator and other operations will be done there. After which, the next hand/route will be executed which will be the module you want to trigger at last.
However, If you want to pass some values from the first hand/route to the last one then you will need to set a variable and fetch it on the second route. See details here : https://www.integromat.com/en/help/converger
Using Aggregator Module
You can either use Array, Text or Numeric Aggregator to aggregate all the iteration operations and then trigger the module that you want to use at last.
As far as my knowledge goes, there is no Integromat default modules that can be configured before the scenario ends. We can leverage the Integromat API in future that is currently in development to do so.
I found a filter to be the most easy way of doing this. Essentially chekcing if this bundle position is equal to the total number of bundles!
If you're interested in doing something on the last iteration only, you can use a filter to check if the current bundle is equal to the total number of bundles
last bundle filter
They won't let me paste pics sigh

Is it possible to filter Task list by other properties than createdBy?

Is there a way to filter the task list ("https://graph.microsoft.com/beta/users/me/tasks") by properties like dueDateTime or completedDateTime?
The request "https://graph.microsoft.com/beta/users/me/tasks?$filter=completedDateTime ge 2016-03-03T00:00:00Z" is accepted but the filter is ignored. The Microsoft Graph Documentation says, that only createdBy is supported.
In my scenario I would like to get all tasks, that have been completed in a certain month.
There is no way to filter tasks by dueDateTime or completedDateTime right now. We have that in the backlog though and plan to add support for such filters in the future.

Efficiently getting all completed tasks

For an application I need all the user's recently completed tasks (recent meaning the last 7 days in this case). I've got it working now, but it's extremely inefficient and in the API reference I can't see a better way to do it.
What I currently need to do is get the current user (https://app.asana.com/api/1.0/users/me), iterate through the user's workspaces and call https://app.asana.com/api/1.0/tasks?workspace=workspaceId&assignee=me&completed_since=sevenDaysAgo for each workspace. This gives me the compact task data for all completed tasks for all projects in that workspace, and also all uncompleted tasks for all projects in that workspace. Since I only need the completed tasks, I need to filter the uncompleted tasks out of that list. However, the compact task data doesn't include the "completed" property. To figure out if a task is completed or uncompleted, I need to get the full task data, which means a call to https://app.asana.com/api/1.0/tasks/taskId per task.
Say I have two workspaces that each have three projects, and each project has on average 100 completed tasks and 200 uncompleted tasks. That means 1 + 2 + (2 * 3) + (2 * 3 * 300) = a whopping 1809 API requests. Apart from this being very slow, it's also a large hit on the Asana servers.
Is there a way to do this more efficiently? Only getting compact task data for completed tasks would go a long way. Getting it in one call would be even better: how does Asana itself do this in My Tasks > View: Recently Completed Tasks, for instance?
(Asana dev here) Have you considered using ?opt_fields=completed in your initial GET /tasks request? You can specifically request any fields you want, see the Input/Output option docs, and of course see Task docs for a reference on available fields. So if you really just want the name (for instance) you could request ?opt_fields=completed,name.
Sadly, you will need to do the filtering out of incomplete tasks on your side.

Getting Asana Task sort order via API

I am trying to get the sort order associated with of within a project. I don't see a field with info in it. When I get the tasks can I assume that order the tasks are in the json is the sort order in the Project? It looks like it that is the case, I just would like confirmation.
Thanks
Randy
When we return the tasks associated with a project we return them in "project priority" order - as in, the order they've been put into manually. If you change the view in the app (say, to sort by hearted) they'll still be in the manual order when fetched via the API.

Resources