0

I'm using Asana API for the first time. What i'm doing is posting the data to the asana-api using python requests library

when running this curl command it works fine.

curl --request  POST -H "Authorization: Bearer 12345678" https://app.asana.com/api/1.0/tasks/1234/addFollowers --data-urlencode "followers=191563290920498"

This works as expected but when using this code i'm getting error

url = "https://app.asana.com/api/1.0/tasks/1234/addFollowers"
headers = {"Authorization":"Bearer 12345678"}
data = {"followers":[191563290920498]}
d =json.dumps(data)
response = requests.post(url,data = d ,headers= headers,verify = False)

Error is

{u'errors': [{u'message': u'Unrecognized request field `followers`. The only allowed keys at the top level are: data, options, auth. Is it possible you did not wrap object properties in a `data` object?', u'help': u'For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors'}]}

The server response is 400,so there must be something wrong in the way i'm passing the data. I've no idea what i'm doing wrong.Any help is appreciated :)

I also have tried this implementation:-

response = requests.post(url,params=d ,headers= headers,verify=False)

in this case the error message is

{u'errors': [{u'message': u'Could not parse request data, invalid JSON', u'help': u'For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors'}]}

and the response code is <400>

https://asana.com/developers/api-reference/tasks#followers

Rohit Kumar
  • 669
  • 3
  • 9
  • 22
  • Is the code shared above _exactly_ what you're using? The error mentions "Followers", but you're passing "followers". Aside from that, have you tried passing `data` directly? E.g. `response = requests.post(url, data=data ,headers=headers, verify=False)` – etemple1 Jun 09 '17 at 17:48
  • @etemple1 that was a typo which is now corrected. to answer your second question yes i have tried it with data=data and in that case error message is this. {u'errors': [{u'message': u'followers: Missing input', u'help': u'For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors'}]} asapa api is restful so i have to pass data in json format – Rohit Kumar Jun 10 '17 at 08:17
  • i don't know what happened now but data=data is working now.:) – Rohit Kumar Jun 16 '17 at 04:28

0 Answers0