0

I'm POST'ing the following JSON to asana's "tasks" endpoint.

{
    "data": {
        "options": {
            "fields": [
                "name",
                "notes"
            ]
        },
        "workspace": <valid number>,
        "assignee": <valid number>
    }
}

It's giving me a "Invalid field" error every time. I've read through the API a few times now and this JOSN looks exactly how the API says it should. Any ideas?

Asana API for those of you who want to help out: Asana API Documentation

DanRedux
  • 9,119
  • 6
  • 23
  • 41

1 Answers1

1

(I work for Asana)

The "options" field is a sibling of the "data" field, not a child. This is mentioned in the docs, but perhaps we aren't providing clarifying examples to make it more obvious.

If you change your request to look like this:

{
    "options": {
        "fields": [
            "name",
            "notes"
        ]
    },
    "data": {
        "workspace": <valid number>,
        "assignee": <valid number>
    }
}

things should work.

Greg S
  • 2,079
  • 1
  • 11
  • 10
  • I have exactly the same JSON as you provided but I'm still getting the invalid field error. There is no phrase being sent back. Here's the array being declared in PHP, and the JSON encoded version looks identical to the one you provided. `array('options'=>array('fields'=>array('name','notes')),'data'=>array('workspace'=>$workspace->id,'assignee'=>$user->id)))` – DanRedux Apr 30 '12 at 19:57
  • I see, the problem may be with some aspect of your request that you didn't mention. Our API accepts both JSON and form-data as input types, but you must set the content type appropriately. Try adding the header: "Content-Type: application/json" – Greg S Apr 30 '12 at 22:37
  • That worked. Strangely, I'm querying `https://app.asana.com/api/1.0/tasks`, passing it the JSON above, but I'm getting a 201 back, which according to the API is a success for object creation. I didn't want to create any tasks, I wanted to query for all tasks. It worked when I was using GET, so I'm almost thinking that POST requests are assumed to be posting something, and GET requests are querying? I even manually set the "options->method" to "GET" but it still made a new task? – DanRedux Apr 30 '12 at 22:51
  • In other words, how can I GET something, but send the info using POST? – DanRedux Apr 30 '12 at 22:52
  • A RESTful API like Asana's will interpret different HTTP methods differently, see: http://en.wikipedia.org/wiki/Representational_State_Transfer - so POSTing to certain endpoints will create, and GET will retrieve. PUT will update, and DELETE will delete. It is better to use GET requests for querying. The "method" option should work as advertised. We will investigate why it's not (could be a bug) but recommend you use GET for the purpose you described. – Greg S Apr 30 '12 at 23:11
  • I'd imagine it is a bug, as the method option should really override it. I feel like it's a bit flaky to depend on the request type at all, just assume it's a GET (no matter the request type), as that's the only safe assumption. This also means in the "method" option you should accept "PUT" AND "UPDATE" as update flags, because update is a much more natural word to signify updating than put is. But it's your API, these are just my suggestions. We use Asana for everything at my workplace, and I'm trying to integrate it into an ajax chat so that we can chat as a team and also share Asana tasks. – DanRedux May 01 '12 at 01:04
  • Oh and I will of course be releasing it to the public for free, as Asana's a great tool. :) – DanRedux May 01 '12 at 01:05