Tips on replicating a template using REST API? (Too slow)

Hi, I’ve made some code in PHP so I can create a new project based on an existing template (since it’s not supported by the API yet). However, it takes about 10 minutes to create everything from scratch with 396 requests!! It’s a little bit too long since there could be more than 1 project to create at the same time and we can,t wait 1 hour until it’s created.

Here are the operations that I do in order:

  1. Create a new project
  2. Add the Custom Fields definition to this project (custom fields already exist in other projects so I just link them)
  3. For each tasks of the template
    3.1) Get the task name and create a new task
    3.2) Add this newly created task to my project
    3.3) Get the template task information (custom fields)
    3.4) Get the template task dependencies
    3.5) Update the newly created task with the information (custom fields, see 3.3)
    3.6) For each subtasks of the template
    3.6.1) Get the template subtask information (due date and name)
    3.6.2) Create the subtask to my newly created task in my project with the information
    3.6.3) Get the template subtask dependencies
  4. Now, my project is created with every task and subtask and all custom_fields are filled. I need to add the dependencies so I loop in an array that bind the template tasks and the new project tasks and then I add the dependency.

As you see, every step is an API request so it gets pretty slow since my template is pretty big. Is there any step that I could optimize (mix requests together) or a better way to do this?

Thanks

I kinda do the same with Templana.com, the only difference is that my template are stored as json object, I don’t have to read the template every time before creating a new project based on it. Maybe that can help! You can also have a look at the Batch part of the API.

I don’t understand how I would do that with Templana.com. Can I link an existing template to that and keep it on my account only (I don,t want others to see it)? Also, if I update my template via asana, will it update on Templana?

The Batch part seems out of question since I would need a lot of changes to my code to make it work and even if it works, it won’t be optimal since the limit is 10 requests per batch but my template often has 12 tasks or more substasks for each task. Would be too complicated in my opinion.

Thanks

The Templana part was just an example. You could indeed create a template in Templana and reuse in, but update in Asana won’t reflect in Templana, this is a manual thing to do.

Do you store your template as json object directly in Templana or do you do it another way? Because if I could just read a JSON to get my template information, it would probably be faster for some operations so I could reduce the amount of requests by half/a quarter.

I have a tool to create a JSON from any project. I load the json on my server and then when a user chooses a template I read the JSON and do API calls.

About you tool to create a JSON from any project, I guess it’s private so you can’t share it? Because it seems interesting enough to me to gain some performances.

Hey @Steven_Simard, sorry that the process is taking too long. Have you tried using the export to JSON option in the Asana web product? That might be helpful. My other idea is to do what Bastien suggested and use the batch API. While it will require changes to your existing code (and be a bit more complex), it will definitely speed up the process. Good luck!

3 Likes

Hi @Jeff_Schneider,

No, I didn’t know that there was an option directly in Asana Web to export a projet into a JSON. Will definitely do and try to update my code and compare the execution time compared to the REST API.

Thanks for helping. Yes the execution is long (10 minutes now) but it’s not critical since there is 5-10 projects per day to create and they don’t need to be created right away so it still works really well in the end.

If it can help someone, I just imported my template and I executed my script.
It’s not really faster in the end (about 8 minutes vs. 9-10 minutes before) since the dependencies aren’t in the JSON. So, for each task and subtask, I still need to do a query to get the dependency (it’s the only ‘GET’ query that I do)

As they said, the batch API seems like the way to go. Not useful for me at this time but seems like our only way unless we get the dependencies in the JSON

1 Like