I am trying to use the Asana API to update and add data to Asana. How do I do it in C#?
I am getting data fine - sample code below:
string apiKey = "xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxx";
var req = WebRequest.Create("https://app.asana.com/api/1.0/workspaces/xxxxxxxxxxxxxxx/projects");
var authInfo = apiKey + ":";
var encodedAuthInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
req.Headers.Add("Authorization", "Basic " + encodedAuthInfo);
var response = new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();
But I don't know how to POST data.
All the examples in their documentation is using Python which I have no experience with.
I have contacted Asana but have yet to hear back. This is what I have so far. I get a 400 error on the last line
var url = "https://app.asana.com/api/1.0/workspaces/xxxxxxxxxxxxxxxxxxx/tasks";
string json =
"\"data\": { " +
"\"workspace\": nnnnnnnnnnnnnnnn," +
"\"name\": \"test\"," +
"\"notes\": \"testing API POST\"" +
"}";
byte[] bytes = Encoding.UTF8.GetBytes(json);
var req = WebRequest.Create(url) as HttpWebRequest;
req.Method = "POST";
req.ContentLength = bytes.Length;
req.ContentType = "application/json";
var requestStream = req.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
var response = req.GetResponse(); //error