Not able to POST new task with JSON request body

I am trying to execute a simple POST request to create a task. I’m using Postman to do this. I can successfully execute this POST request if I use the x-www-form-urlencoded option for the request body. However, when I try to submit the request with the body as raw JSON, I get the following response:

{
“errors”: [
{
“message”: “You should specify one of workspace, parent, projects”,
“help”: “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
}
]
}

Here is the JSON request body I’m trying to use (obviously i changed the value for “projects”):

{
“due_on”: “2019-10-11”,
“name”: “My first API task raw json”,
“notes”: “here are some notes”,
“projects”: 123456789
}

Can someone please let me know why I’m getting this error when I’ve clearly specified a project for the task to be created under? I’ve also tried these variants for the value of “projects”:

“projects”: [{123456789}]
“projects”: {123456789}
“projects”: [{“id”: 123456789}]

Hi @Brendon_Davies and welcome to the forum!

You need to wrap your JSON in a “data” tag. Also all IDs are now strings so your project ID should be a string:

{
  "data": {
    “due_on”: “2019-10-11”,
    “name”: “My first API task raw json”,
    “notes”: “here are some notes”,
    “projects”: "123456789"
  }
}

Try that!

1 Like

@Phil_Seeman thank you so, so much! that works exactly as expected.