How to consolidate API calls for the ASANA API - api

I'm a freelance web dev and I work with a lot of clients across many different workspaces in Asana. Not being able to get a consolidated view makes this a tedious and difficult thing to manage, so I'm putting together my own little utility to help me get a 'superview' of tasks assigned to me in order of the due date. In order to make this easier for me to scan, I need to have the project name next to the task details.
The easiest way, in my mind, would be a single API call for all tasks assigned to me and request the project name, task name, task id, due date, and workspace name all at once.
The API doesn't seem to allow this consolidated type of request, however, so instead, the workflow goes something like this;
API call to get all my workspaces
Loop through the workspaces, making an API call for each to get all tasks
Use PHP to sort those tasks accordingly
Loop through those tasks making an API call for the first instance of each project in order to get the project name (I cache the data as I
go so that I'm only making a call once per project)
The issue I'm getting is a 500 error when I start making API calls to get the project details. I doubt I'm hitting the 100 call per minute limit, but I'm still getting the errors none the less. In light of this, I'm looking for a way to make a consolidated call that contains all the data I need, but I can't seem to figure it out.
Anyone have some guidance on this?

Good news! We actually do support Input/Output options that allow you to specify which fields you want, including nested fields. So, while you still need to make separate calls for each workspace, you can do something like this:
workspaces = GET /workspaces
for id in workspaces
tasks = GET /workspaces/:id/tasks?assignee=me&opt_fields=name,due_on,projects.name
(If you're only interested in incomplete tasks, you can add &completed_since=now - or if you want incomplete and recently completed tasks, &completed_since=... with the timestamp you want to exclude any tasks that were completed before)
Additionally, 500 is not the code we send for rate limiting - it's likely an issue with the request itself. How are you requesting the project details?

Related

ASP.NET Core Web API - Measuring response data

We have an ASP.NET Core Web API project. Today on accident I found an API method that was returning unnecessary amounts of data.
In my example we were returning users along with countries which is what we needed, but we were also returning a list of cities for each country so that was a tremendous amount if data, I was able to reduce it from 7MB to 23KB (per Insomnia client).
I was able to fix this by performing a select and creating a new country object and not passing in the cities property. I am not even sure if that's the right way to fix that problem but I will leave that for another time. My question is...
Is there a tool/nuget package out there that would provide this type of info? I'd like to get an idea on how much data we are sending to the clients when different methods are called. We have app insights but I don't believe it provides that data or at least I don't see it.
Thank you!
I was able to resolve this issue by writing some middleware code that logs the results to azure application insights, here is a copy of the code if anyone needs it:
https://gist.github.com/tekguy/52b245f6582158d7240f80bf46c4cc71
You can then query this info by using app insights log query:
requests
| order by timestamp desc
| project url, customMeasurements.Size

Is there a better way to trap Xero API errors?

I am writing some code in vb.net 2013 Express to access Xero accounting via a private application, and it's working fairly well. However I have come across a problem when trying to write some code to upload multiple contacts from a single XML file. I parse the XML, create a new contact from each line, and add it to a list of contacts. I then submit these to Xero:
try
dim sResult = private_app_api.Create(mContacts)
Catch ex As Xero.Api.Infrastructure.Exceptions.ValidationException
' do something with ex to determine what went wrong
end try
If all contacts create correctly, sresult contains a list of those contacts with their Xero-GUIDs, which I then need to feed back up to the system they are being sent from. This all works correctly.
If one or more of the contacts does not create for some reason, I get a list of one or more errors in the ex.ValidationErrors() collection, but I get nothing in sresult. So, I don't have a reference back to those that have worked, only those that have not.
To get around this, I am looping through each contact and pre-checking that they don't already exist on Xero, and don't have a duplicate name. This also works, and means that I only submit contacts that I know are not already on Xero.
My worry now, though, is that I am going to run into the Xero API limits of 60 calls in a rolling 60-second window. I am trying to make the code robust by pre-checking most of the common things that could cause a problem, but every time I do that, I get closer to the limit, which in theory means that I need to add some complexity by trying to throttle calls to Xero.
Is there a better way that I can call .create() and get both the successful information and the error information?
I think the way around this seems to be to add a reference to RateLimiter when I first create the API object. This appears to implement a means where any calls that would exceed the rate limit are automatically paused. It seems necessary, though, to set the limit a little lower than 60 per 60-second rolling window, as I still get rate errors at that. I set it to 50, and my test code now waits a little while once it runs over the limit.
I haven't figured out how to implement both the 60/60s limit and the 5000/24h limit, though.

Present variable information within a single mturk HIT

I'd like to use mturk to have 10 workers visit my website, log in with a test account, and enter some information on their profile. I don't want them to see each other's entries, so each worker should get login information for a different test account when they view the HIT.
This almost looks like what mturk's template feature is for -- I could upload a CSV with the information for each test account. But if I understand correctly, that will make 10 separate HITs, and allow one worker to do all 10 of them. Is there any way to have mturk put information that varies between workers into a single HIT?
Here are the solutions I'm currently aware of:
Use the CLI to automate creation of a bunch of different HITs. This would be a lot of work, and also make approving and retrieving the results cumbersome.
Direct workers to a survey website that's capable of doing what I want, and have them get the login information there.
Dynamically fill in part of the HIT using an AJAX request to an external website and database. That seems like crazy overkill for something so simple.
Are there other options?

Get all task information via API from asana

i'm writing a simple application to build a task dependency tree (i declare a dependency by commenting on a task "Depend on: ") using asana API, it is indeed a simple task and should also be a simple and quick script, but i got to a bottle neck here.
From the API documentation i get that i need to:
Query the project tasks using /project//tasks
iterate trough tasks to:
get complete task information, since i'm only getting id and name.
Get task stories.
what i would like to do is a simple api call to get all this information at once, like:
/project//tasks options.expand {task, stories}. Am i missing something or this it not possible?
Complete information about tasks you can get with one request thanks to "opt_fields" option (https://asana.com/developers/documentation/getting-started/input-output-options).
Unfortunately "stories" still need another request.
No. As seen in the asana queries are tree-like structure. To get the story you require workspace_id > project_id > task_id & task_id for story. I recommend that you use a loop. Tasks of the project for getting information on the tasks and history. Upon receipt of the task id - send two requests info task & stories. Thank you, Ruslan.

Getting asana "now" tasks and "today" tasks under project and user via API

From within Asana, we can see how the tasks are split into "Now", "Next" and "later" in project view as well as "Today", "Upcoming" and "later" in user. I can't seem to find the API required to identify the tasks in each category. Is this functionality available for developers?
(I work at Asana)
In the reference for Tasks at https://asana.com/developers/api-reference/tasks, the docs describe the assignee_status field. This will give you the today/upcoming/later status for a task assigned to a user.
In project view, these statuses don't exist so I assume that by now/next/later you are referring to "priority headings", or arbitrary labels that you are able to create inside any list by ending the name of a task with a colon (:). There is not currently a way to find out which priority heading a task is under via the API.
If knowing the priority heading containing a task is important, you could iterate over the results (which by default show up in the same order they do in the UI), keeping track of which priority heading you saw last. This is inelegant and prone to problems if you filter the task list in some way (and possibly don't get all the priority headings as a result), but it might help you get the job done until a better solution is provided.
If you are querying for a list of tasks, make sure you add the opt_fields=assignee_status parameter and that field will be provided in each of your results.