I have Asana Premium. I have code that uses API to get task information. I get the task info just fine. I then need to get last story date/time - I am looking for tasks that are sitting without activity. For some reason I am getting the following response:
“StatusCode: Unauthorized, Content-Type: application/json; charset=UTF-8, Content-Length: 231)”
I can use the same URL in a web browser to get the json manually so I know that I can GET the info.
What could be wrong?
My code:
button2.Enabled = false;
var client = new RestClient(@"URL REMOVED BUT THIS ONE GETS A RESULT");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer " + asanaToken);
IRestResponse response = client.Execute(request);
if (!response.IsSuccessful)
{
Log.Error(response?.ErrorException?.Message);
Log.CloseAndFlush();
MessageBox.Show("There was an error connecting to Asana. Please contact Engineering.");
}
else
{
TaskRootObject JSONObj = JsonConvert.DeserializeObject<TaskRootObject>(response.Content);
//Loop through the tass and get stories
foreach (Task item in JSONObj.data)
{
string url = String.Format(@"https://app.asana.com/api/1.0/tasks/{0}/stories", item.gid);
var storiesClient = new RestClient(url);
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var storiesRequest = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer " + asanaToken);
IRestResponse storiesResponse = client.Execute(storiesRequest);
}
asanaListView.Objects = JSONObj?.data;
asanaListView.Sort(Status, SortOrder.Ascending);
}