Is there introductory documentation on how to begin with the API using C#?
I found this code which I am trying:
public string GetUsers()
{
var req = WebRequest.Create(“https://app.asana.com/api/1.0/users”);
SetBasicAuthentication(req);
try
{
return new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();
}
catch (System.Net.WebException exWeb)
{
return “Error”;
}
}
I’m not sure if your WebRequest-handling code is exactly correct or not but there are issues with your SetBasicAuthentication routine. First, I’m not sure why you’re adding the “:” to your apiKey but that shouldn’t be done. Second, change "Basic " to "Bearer ". Lastly, are you setting “apiKey” to the value of a Personal Access Token that you generated? Unless you’re using OAuth for authorization, “apiKey” will need to be a Personal Access Token.
Right, you are not Paul! That’s what I get for skimming.
Anyway, I knew it was something obvious/stupid. When I tried this line: var asana = new Asana(YOUR_API_KEY, AuthenticationType.Basic, errorCallback);
It said type/namespace asana can’t be found. How do I get the libraries?
Hmmm interesting on that StackOverflow post - the only thing I can think of is that perhaps the API has changed since 2012 when that post was made.
It looks like here you’re trying to use the AsanaNet library I mentioned? If so, you’ll need to download and compile the library from that Github repo and reference it in your test app.
What exactly do I download and compile? I’m not using Python or javascript or Ruby… That is why I specifically titled this thread “C# Documentation”. Mine is a C# Windows desktop application.
OK, so now I am calling successfully into the asana DLL and I realize all the WebRequest code I had written is in the DLL so I don’t need any of that.
However, I am not getting anything written to my Output window when this executes:
var asana = new Asana(apiKey, AuthenticationType.Basic, errorCallback);
asana.GetMe(o =>
{
var user = o as AsanaUser;
Console.WriteLine("Hello, " + user.Name);
System.Diagnostics.Debug.WriteLine("Hello, " + user.Name);
});
asana.GetWorkspaces(o =>
{
foreach (AsanaWorkspace workspace in o)
{
Console.WriteLine("Workspace: " + workspace.Name);
System.Diagnostics.Debug.WriteLine("Workspace: " + workspace.Name);
}
});
I’d suggest wrapping that code in a Try/Catch block then stepping through it line by line in the debugger - you’re probably hitting an error somewhere and that’ll help you determine if you are, and on what line, and by examining the exception details, what the error is.
No errror…no output.
I changed the code somewhat so I could better interrogate the variables. sReturned is empty string. sbReturned.ToString() is empty string. So it’s not working but there are no errors indicating what is wrong.
string sReturned = “”;
StringBuilder sbReturned = new StringBuilder();
try
{
//var asana = new Asana(apiKey, AuthenticationType.Basic, (s1, s2, s3) => { });
var asana = new Asana(apiKey, AuthenticationType.Basic, errorCallback);
I am still trying to find out what is wrong. I am back at the documentation reading how to get started. I thought maybe I had to register my app so Asana knows it has my permission. It is a windows application. But the registration page said APP NAME and APP URL. There is no url as it is not a web application. Is this the correct way to get started accessing Asana and if so, what information do I need to give it?