I see some questions that have been asked of how to create tasks using an API, but I want to know how to create a new project.
I have predetermined format of how I want to create a new project every time that I want to create a new one. There are specific tasks that I have and each one has its own subtasks. Right now I have a template on Asana and every time I want to create a new project I go to that project and make a copy of it and rename it to what my current project is.
Does anybody know of a way to automate this using Python, this way I can just run the script and put in the details of the name of the project and it will automatically create a new project on Asana (this way if I need to make 5 projects at once I can just make a list of all project names and loop through all of them)?
I know that you need to have a key and I have something which is called API_KEY and is 32 characters long.
ADD ON: Here is the code that I use in Python to access all of the tasks and subtasks in my workspace in Asana:
import asana
api_key = '################################' //my private key goes here
client = asana.Client.basic_auth(api_key)
me = client.users.me()
all_projects = next(workspace for workspace in me['workspaces'])
projects = client.projects.find_by_workspace(all_projects['id'], iterator_type=None)
for project in projects:
if 'Template' not in project['name']:
continue
print(project['name'])
project_id = project['id']
tasks = client.tasks.find_by_project(project_id, iterator_type=None)
for task in tasks:
print(" " + task['name'])
task_id = task['id']
task_subtasks = client.tasks.subtasks(task_id, full_payload=True)
for subtask in task_subtasks:
print(" " + subtask['name'])
When I run this I get all of my tasks and subtasks for the projects that have the word 'template' in their titles. So, this is how to read, is there that if I save all of this in a JSON format, then every time I want to create a new project I can just upload that JSON and get a new project?
To create a project in asana you need to get workspace or you need to get team id. I created one using workspace. These are steps :-
In python this is code
import asana
client = asana.Client.basic_auth('ASANA_KEY')
project = {'name':'test','workspace':'WORKSPACE_ID'}
client.projects.create(project)
This will create the project on your account. It did in my case. To create a task follow this procedure.
Run this code then
a={'name':'abc','projects':'PROJECT_ID','workspace':'WORKSPACE_ID'}
client.tasks.create(a)
This will create task under the project whose id you are providing.