Hi! We have an api in python that is set up to create a project for a request coming in from Knack. We want to have one of the tasks get added to a project that is already created, but I’ve looked at the information and it’s not really coded in the same way our code is.
def create_tasks(self, tasks, project_id):
resolved_tasks = self.resolve_tasks(tasks)
section_id = None
created_task_ids = []
for task in resolved_tasks:
try:
if section_id is not None:
task['memberships'] = [{'project': project_id, 'section': section_id}]
task['projects'] = [project_id]
custom_fields = {}
estimated_hours = task.pop('estimated_hours', None)
if estimated_hours is not None:
custom_fields[self.estimated_hours_field_id] = estimated_hours
task['custom_fields'] = custom_fields
subtasks = task.pop('subtasks', ())
res = self.asana.tasks.create(task)
created_task_ids.append(res['id'])
for subtask in subtasks:
sub_res = self.asana.tasks.add_subtask(res['id'], subtask)
created_task_ids.append(sub_res['id'])
except Exception:
logging.exception('Exception while creating task {}'.format(task))
self.rollback_tasks(created_task_ids)
raise
if task['name'].endswith(':'):
section_id = res['id']
**if task['name'].endswith('Status'):**
** addProject[‘memberships’] = [{‘project’: #####, ‘section’: #####}]**
return created_task_ids
- I found the number and the section but didn’t want to post them…
Also it’s not breaking from sending the tasks to asana, it just doesn’t add them.