Getting a 400 exception when calling add_project_for_task

Hi, I’m using the API to duplicate another task, then I want to move it to another project, by first adding it to the new project, then removing it from the project I duplicated it from. I do this in the Mac client all the time, but getting a 400 “task: Not the correct type” error from add_project_for_task…

{‘data’: {‘project’: ‘8186841131256’}}

try:
api_response = tasks_api_instance.add_project_for_task(body, newtaskid)
print(api_response)
except Exception as e:
print(“Exception when calling TasksApi->add_project_for_task: %s\n” % e)

This gives me the following error:
Exception when calling TasksApi->add_project_for_task: (400)
Reason: Bad Request

HTTP response body: b’{“errors”:[{“message”:“task: Not the correct type”,“help”:“For more information on API status codes and how to handle them, read the docs on errors: Errors”}]}’

I confirmed the duplicated task is of type “default_task”, so not sure what type it’s looking for.

Thanks,
Jim

Hi @jimson ! This response indicates that the GID you’re passing as newtaskid is a recognized Asana object, but it’s not a task. Could you add some extra logging to confirm exactly what’s being passed to add_project_for_task? If it does turn out to be a valid task GID, please feel free to open a support request with a more complete code snippet and the task GID included, we’ll take a look.

Mikhail, you are correct. I was grabbing the incorrect gid from the duplicate_task response. Not sure what the first ‘gid’ is (duplicatation request gid?) but I needed new_task.gid.

It works with the correct gid

Thanks,
Jim