Unable to create a task using asana api in C#

Hi Team,

I am creating a task using asana api in C# (.NET). However i am getting a error as 404 not found.

Please find the below code.

string workspace = “113577*******3”;
string name = “Hello world”;

            string data = "{\"data\": { \"workspace\":\"" + workspace + "\", \"name\":\"" + name + "\"}}";

            Log("Asana event start :: " + data);
            Log("CreateAsanaTasks :: " + Authorizationkey);

            
            var httpgetasanatask = (HttpWebRequest)WebRequest.Create("https://app.asana.com/api/1.0/tasks");
            httpgetasanatask.ContentType = "application/json; charset=UTF-8";
            
            httpgetasanatask.Headers.Add("Authorization", "Bearer *********");
            httpgetasanatask.Method = "POST";                
            httpgetasanatask.Timeout = 5000;
            httpgetasanatask.ReadWriteTimeout = 5000;

            byte[] dataBytes11 = UTF8Encoding.UTF8.GetBytes(data);
            using (Stream postStream = httpgetasanatask.GetRequestStream())
            {
                postStream.Write(dataBytes11, 0, dataBytes11.Length);
            }

            HttpWebResponse httpresponse21 = httpgetasanatask.GetResponse() as HttpWebResponse;
            var d1 = new StreamReader(httpresponse21.GetResponseStream());

The payload getting created for the api is
{“data”: { “workspace”:“113577******”, “name”:“Hello World”}}

Hi @Swapnil.G,

(FYI I moved your post to the Developers & API section, that’s a better place for these coding discussions.)

You should be getting a message back along with the 404 error, which will give you some additional info on the problem - what does the message say?

I am getting the WebException and the Message just say “The remote server returned 404 not found” I am not getting any additional info

Hi @Swapnil.G,

I ran your code to verify that it’s correct, which it is.

The 404 error means that the workspace ID you’re passing is not found; i.e. it’s either not a valid workspace ID or it’s a workspace that’s not accessible to the auth token you’re using.