0

I am trying to create Asana task using oAuth, so far it was working fine, but suddenly its not working anymore.

It is throwing back the following response:

{"errors":[{"message":"missing both `parent` and `workspace` fields; at least one required"}]}

Here is what I am doing

import requests
import json

data = {
    'workspace':'<my workspace id>',
    'assignee':'me',
    'name':'My awesome task',
    'notes':'My task notes'
}
headers ={'Authorization':'Bearer <my token>','Content-Type':'application/json'}
response = requests.post('https://app.asana.com/api/1.0/tasks',
                         headers=headers,
                         data=json.dumps(data))
print response.text
Maddy
  • 791
  • 1
  • 8
  • 22

1 Answers1

0

It looks like you're missing a data parameter in the payload. It's a common gotcha, but when you post JSON data to the API you need to send something that looks like this:

{ "data": { "name": "This is my task", "workspace": 1234, ... } }

In this case, you should be able to fix it by simply changing the last parameter to data=json.dumps({ 'data': data }).

Hope that helps!

agnoster
  • 3,744
  • 2
  • 21
  • 29
  • Thanks But i just removed Content-Type header and sending raw dict to requests.post() and it worked! – Maddy Oct 24 '14 at 09:11