Asana / python-asana

Official Python client library for the Asana API v1
MIT License
299 stars 103 forks source link

'update_task' not updating 'start_on' #133

Closed davidorme closed 2 years ago

davidorme commented 2 years ago

Hi,

We're looking at moving to Asana and using some python scripts to implement some custom behaviour (like pulling start dates forward when dependencies are completed - this works using Rules via the web app but reduces the dependent duration to a single day). The problem I'm having is that I can't seem to move start dates - I've seen the note in the API docs about needing to provide start_on and due_on, but it doesn't seem to work. The call goes through, but the returned data for the updated task has an unchanged start_on value.

In [144]: client = asana.Client.access_token(token) 
     ...: client.headers={'asana-enable': 'new_user_task_lists'} 
     ...:                                                                                                                                     

In [145]: dep_task = client.tasks.get_task(this_dependent['gid']) 
     ...: print(dep_task['start_on']) 
     ...: print(dep_task['due_on']) 
     ...:                                                                                                                                     
2021-12-04
2021-12-08

In [146]: response = client.tasks.update(this_dependent['gid'],  
     ...:                                {'data': {'start_on': '2021-11-25', 'due_on': '2021-12-08'}})                                        

In [147]: print(response['start_on']) 
     ...: print(response['due_on']) 
     ...:                                                                                                                                     
2021-12-04
2021-12-08

Any suggestions?

davidorme commented 2 years ago

OK - I have just spotted that I used client.tasks.update not client.tasks.update_task. The current code in master in tasks.py suggests .update, but the API docs have .update_task. Both seem to do something, but neither updates.

In [150]: response = client.tasks.update_task(this_dependent['gid'],  
     ...:                                {'data': {'start_on': '2021-11-25', 'due_on': '2021-12-08'}}) 
     ...: print(response['start_on']) 
     ...: print(response['due_on']) 
     ...:                                                                                                                                     
2021-12-04
2021-12-08
davidorme commented 2 years ago

CURL works. I'm wondering if it is the quotes?

curl -X PUT https://app.asana.com/api/1.0/tasks/<redacted> \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer <redacted> \
  -d '{"data": {"start_on": "2021-11-25", "due_on": "2021-12-08"}}'
davidorme commented 2 years ago

OK - nope. It is wrapping the body in {'data': {}} that is the issue. My mistake

In [160]: response = client.tasks.update(this_dependent['gid'],  
     ...:                                params= {"start_on": "2021-11-25", "due_on": "2021-12-08"}) 
     ...: print(response['start_on']) 
     ...: print(response['due_on']) 
     ...:                                                                                                                                     
2021-11-25
2021-12-08