Vivek Patel
Vivek Patel

Reputation: 11

ASANA API How to Update Subtask

I am trying to update a subtask. More specifically just the due date. I have tried several things and have failed. This is what I have tried so far:

Attempt 1: URL: https://app.asana.com/api/1.0/tasks/ JSON: {"data":{"due_on":"6/18/2017 12:00:00 AM"}} Error: The remote server returned an error: (400) Bad Request.

Attempt 2: Added a parent id to JSON request URL: /tasks/ JSON: ParentID is masked for security reasons {"data":{"due_on":"6/18/2017 12:00:00 AM","parent":{"id":################,"name":null}}} Error: The remote server returned an error: (400) Bad Request.

attempt 3: using /subtask in URL URL: /tasks//subtasks/ JSON: {"data":{"due_on":"6/18/2017 12:00:00 AM"}} ERROR: The remote server returned an error: (404) Not Found

What should be the correct URL to send the JSON request and what should be in the request to modify the subtask due date ?

Any help is greatly appreciated. Thanks Viv

Upvotes: 1

Views: 289

Answers (1)

Matt
Matt

Reputation: 10564

Vivek,

The first thing I noticed is that the URL doesn't contain the ID of the task you're trying to update - I'm not sure if this is a copy-paste omission in the question, but if not and the URL you're using doesn't have the ID of the task, we won't know which task you're trying to set the due date for - so that might be one thing you're seeing :)

Additionally, I'd like to verify that you're using the HTTP verb PUT for these requests; you can POST new tasks in Asana, but to change fields on an existing task, we expect a PUT. Since subtasks count as tasks in Asana, this can be done just against https://app.asana.com/api/1.0/tasks/:task_id route

One more thing: setting the due date or due time in Asana are actually 2 separate things - most tasks have their due date set, but in our web app you can choose to add the time when setting the due date. This is represented in our API by the fields due_on for dates and due_at for times. If you just want the due date (inferred by the fact that the time is 12:00 AM) you'll probably want due_on and a string whose format is YYYY-MM-DD (in this case, 2017/06/18). If you want to set the actual time, you can use due_at with an ISO8601 timestamp, such as 2017-06-18T08:00:00Z

Putting it all together, here's a curl request I tested here with "due_at" to keep the time aspect in:

curl --request PUT \
--header "Authorization: Bearer $ASANA_PERSONAL_ACCESS_TOKEN" \
"https://app.asana.com/api/1.0/tasks/$TASK_ID" -d '{
  "data": {
    "due_at": "2017-06-08T12:00:00Z"
  }
}'

Finally, and completely unrelated: do you happen to be the Vivek Patel currently working for Yelp? If so, I used to work with you at Sharpcast - small world! If not, no worries, feel free to ignore!

Upvotes: 2

Related Questions