Showing posts with label rest service. Show all posts
Showing posts with label rest service. Show all posts

Wednesday, 29 January 2014

Notes on accessing AtTask REST service for Project Status reporting

AtTask is used as our project management software. The REST service for it lives here:

https://[yourcompanynamehere].attask-ondemand.com/attask/api/

The documentation is here.

To get info on projects:

https://[yourcompanynamehere].attask-ondemand.com/attask/api/project/search?



To get info on tasks:

 https://[yourcompanynamehere].attask-ondemand.com/attask/api/task/search? will return task information.

To get all of the fields for a project you can add 'field=*' to the query string.

https://[yourcompanynamehere].attask-ondemand.com/attask/api/project/search?fields=*


To just get specific fields pass the field names as comma separated.

https://[yourcompanynamehere].attask-ondemand.com/attask/api/project/search?fields=actualCost,actualCompletionDate


To filter put the field name and the value you want:

https://[yourcompanynamehere].attask-ondemand.com/attask/api/project/search?status=CUR


From .net you can use the System.Net.Http.HttpClient object to call the above URLs. You need to tell the HttpClient object that it's cool to get back a JSON response so you need to add a handler to it, something like this:

var proxy = new WebProxy
                {
                    Address = new Uri(proxyUri),
                    Credentials = CredentialCache.DefaultNetworkCredentials
                };

var handler = new HttpClientHandler
                    {
                        PreAuthenticate = true,
                        ClientCertificateOptions = ClientCertificateOption.Automatic,
                        UseProxy = true,
                        Proxy = proxy
                    };

var client = new HttpClient(handler) {BaseAddress = new Uri(baseUrl)};

// make it so we accept json as a response
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage response = client.GetAsync(url).Result;


Then use the System.Web.Script.Serialization.JavaScriptSerializer to map the JSON into .Net objects:

var serializer = new JavaScriptSerializer();

var projects = serializer.Deserialize<IList<Project>>(json);

Where your Project object contains all the fields you are expecting from the JSON

public class ProjectDto
{
    public string ID { get; set; }
    public string name { get; set; }
    public string objCode { get; set; }
    public string percentComplete { get; set; }
    public string plannedCompletionDate { get; set; }
    public string plannedStartDate { get; set; }
    public string priority { get; set; }
    public string projectedCompletionDate { get; set; }
    public string status { get; set; }

}


You can use the above data to make reports based on real time project status: