.NET

The samples below are written in C#, targets .NET Framework v4.0 and uses the additional libraries Newtonsoft.Json and System.Net.Http. Both of these libraries are included in the sample project that are available for download below.

Download .NET samples

Sample 1: Get Articles

Fetches a list of articles. No authentication is needed.


        
        using System.Net.Http;
        using System.Net.Http.Headers;

        using Newtonsoft.Json.Linq;

        public class Program
        {
            public static void Main(string[] args)
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri("https://qrapi-se.gcelsa.com/");

                    // Add an Accept header for JSON format.
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = client.GetAsync("api/Article/GetArticles").Result;

                    response.EnsureSuccessStatusCode();

                    // Fetch the results from the request as a json string.
                    var json = response.Content.ReadAsStringAsync().Result;

                    // Convert the json string to a dynamic object so we easily can access its properties.
                    dynamic apiResponse = JObject.Parse(json);

                    // Response code 0 indicates success. See API documentation for a description of the error codes.
                    if ((int)apiResponse.ResponseCode != 0)
                    {
                        throw new ApplicationException((string)apiResponse.ResponseDescription);
                    }

                    foreach (var article in apiResponse.ResponseObject)
                    {
                        Console.WriteLine("Id: {0}\nArticleName: {1};\nDescription: {2}\n\n", article.Id, article.ArticleName, article.Description);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\nAn error occurred!");
                    Console.WriteLine("Message :{0} ", ex.Message);
                }
            
                Console.ReadLine();
            }
        }
        

        

Sample 2: Get Projects

Fetches a list of projects. Basic authentication is used.

Note: The username and password placeholders must be filled in before use.
        
        using System.Net.Http;
        using System.Net.Http.Headers;

        using Newtonsoft.Json.Linq;

        public class Program
        {
            public static void Main(string[] args)
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri("https://qrapi-se.gcelsa.com/");

                    // Add an Accept header for JSON format.
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    string apiUser = "[ENTER YOUR API USER HERE]";
                    string apiPass = "[ENTER YOUR API PASS HERE]";
                    string user = "[ENTER YOUR SYSTEM USER HERE]";
                    string pass = "[ENTER YOUR SYSTEM PASS HERE]";

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", apiUser, apiPass))));
                    client.DefaultRequestHeaders.Add("UserName", user);
                    client.DefaultRequestHeaders.Add("UserPassword", pass);

                    HttpResponseMessage response = client.GetAsync("api/Project/GetProjects").Result;

                    response.EnsureSuccessStatusCode();

                    // Fetch the results from the request as a json string.
                    var json = response.Content.ReadAsStringAsync().Result;

                    // Convert the json string to a dynamic object so we easily can access its properties.
                    dynamic apiResponse = JObject.Parse(json);

                    // Response code 0 indicates success. See API documentation for a description of the error codes.
                    if ((int)apiResponse.ResponseCode != 0)
                    {
                        throw new ApplicationException((string)apiResponse.ResponseDescription);
                    }

                    foreach (var project in apiResponse.ResponseObject)
                    {
                        Console.WriteLine("Id: {0}\nProjectName: {1}:\nExternalCode: {2}\n\n", project.Id, project.ProjectName, project.ExternalCode);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\nAn error occurred!");
                    Console.WriteLine("Message :{0} ", ex.Message);
                }

                Console.ReadLine();
            }
        }

        

Sample 3: Update Project

Updates a specific project. Basic authentication is used.

Note: The username and password placeholders must be filled in before use.
        
        using System.Net.Http;
        using System.Net.Http.Headers;

        using Newtonsoft.Json.Linq;

        public class Program
        {
            public static void Main(string[] args)
            {
                try
                {
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri("https://qrapi-se.gcelsa.com/");

                    // Add an Accept header for JSON format.
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                
                    string apiUser = "[ENTER YOUR API USER HERE]";
                    string apiPass = "[ENTER YOUR API PASS HERE]";
                    string user = "[ENTER YOUR SYSTEM USER HERE]";
                    string pass = "[ENTER YOUR SYSTEM PASS HERE]";

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", apiUser, apiPass))));
                    client.DefaultRequestHeaders.Add("UserName", user);
                    client.DefaultRequestHeaders.Add("UserPassword", pass);

                    var requestJson = @"{
                      ""ProjectName"": ""sample string 1"",
                      ""ExternalCode"": ""sample string 2"",
                      ""Id"": 220,
                      ""ProjectTypeId"": 3
                    }";

                    HttpResponseMessage response = client.PostAsync("api/Project/UpdateProject", new StringContent(requestJson, Encoding.UTF8, "application/json")).Result;

                    response.EnsureSuccessStatusCode();

                    var responseJson = response.Content.ReadAsStringAsync().Result;

                    // Convert the json string to a dynamic object so we easily can access its properties.
                    dynamic apiResponse = JObject.Parse(responseJson);

                    // Response code 0 indicates success. See API documentation for a description of the error codes.
                    if ((int)apiResponse.ResponseCode != 0)
                    {
                        throw new ApplicationException((string)apiResponse.ResponseDescription);
                    }

                    Console.WriteLine("Request OK");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\nAn error occurred!");
                    Console.WriteLine("Message :{0} ", ex.Message);
                }

                Console.ReadLine();
            }
        }