Could not parse request data, invalid JSON c#

I have managed to get values without issues, but when I tried doing a POST to create a new project, I get the 400 Bad Request with reason being it can’t parse my request data, invalid JSON.

I’ve created the class structure and I use to serialize the data into a json string (done this hundreds of times) and passing that in with the post call. I’ve even double checked the string and made sure it looked correct. I guess I’m just trying to figure out what I’m missing.

Thank you for any help you can provide.

To add I do have the data as part of the json as I followed the example json when I designed the class.

I’ve switched some things up and I feel like I’m closer, however I’m getting this error now.
parent: Not the correct type. I’m actually trying to create a task now on an existing project.

Which I don’t understand since I have it as a string as it shows in the example…

Hi @Christopher_Brown and welcome to the forum,

Please post your complete request so we can see exactly what you’re sending to Asana.

1 Like

That’s a VB sample but .net is .net. so it may help.
I have not tested it but I think it should work.

Dim info As New JObject
info.Item("data") = New JObject
Dim projects As New JArray
info.Item("data").Item("projects") = projects
info.Item("data").Item("name") = "new task name"
Dim cl As New WebClient
cl.Headers.Add("Content-Type", "application/json; charset=utf-8")
dim url as String = ""
Dim resp = cl.UploadString(url, "POST", info.ToString)

I’m currently using this structure

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TaskData
public class CompletedBy
public string name { get; set; }

public class External
    public string data { get; set; }
    public string gid { get; set; }

public class Data
    public string approval_status { get; set; }
    public string assignee { get; set; }
    public string assignee_status { get; set; }
    public bool completed { get; set; }
    public CompletedBy completed_by { get; set; }
    public DateTime due_at { get; set; }
    public string due_on { get; set; }
    public External external { get; set; }
    public List<string> followers { get; set; }
    public string html_notes { get; set; }
    public bool liked { get; set; }
    public string name { get; set; }
    public string notes { get; set; }
    public string parent { get; set; }
    public List<string> projects { get; set; }
    public string start_on { get; set; }
    public List<string> tags { get; set; }
    public string workspace { get; set; }

public class CreateTaskData
    public Data data { get; set; }


I populated some of the entries for the task, but I did less here vs what I tried for project creation. Note that the class structure is based on the sample json in the API docs.

I’m getting this json string

“data”: {
“approval_status”: null,
“assignee”: null,
“assignee_status”: null,
“completed”: false,
“completed_by”: null,
“due_at”: “0001-01-01T00:00:00”,
“due_on”: null,
“external”: null,
“followers”: null,
“html_notes”: null,
“liked”: false,
“name”: “VoiceOver1”,
“notes”: “My VO holder project”,
“parent”: “projectID”,
“projects”: [
“start_on”: null,
“tags”: null,
“workspace”: “workspaceID”

This gives me the error “parent: Not the correct type”
The parent ID I was able to retrieve for the project and I’m using the same ID for parent and under projects.

Ah, OK.

parent refers to a parent task when you’re creating a subtask. It doesn’t have anything to do with projects. Those go in the projects field, which it looks like you’re already doing. Don’t specify parent for a top-level task.

1 Like

Ah, that makes sense. However, I did try deleting the parent field so it would be null, but then I get a 500 error with this response message

{“errors”:[{“message”:“Oops! An unexpected error occurred while processing this request. The input may have contained something the server did not know how to handle. For more help, please contact and include the error phrase from this response.”,“phrase”:“13 massive roosters race calmly”}]}

A couple of notes:

For all of the “null” fields, just remove them instead of sending them with null. Sending wth null shouldn’t cause any issues with roosters :slight_smile: or otherwise, it’s just cleaner and more efficient.

I think the error is from your Due At; Asana doesn’t go back that far. Try making that an actual recent date and see if that makes those racing roosters happy.

1 Like

Ok, I fixed the datetime, it was the default value. That alone didn’t fix it, but removing the nulls did. So it appears one of the nulls was certainly creating an issue.

Thank you for the assistance. This may have been part of the issue I had with project creation as well, but I think that will be fine now as well.

1 Like

I’ll bet it was that you had both due_at and due_on before removing the nulls; you’re only allowed to include one or the other. But anyway, sounds like you’re good to go now!

That’s still helpful information to know as to why it was throwing the error.

1 Like