From a57713ea966be565b24a24198ff3fde6e7c2efc8 Mon Sep 17 00:00:00 2001 From: Fredy Whatley Date: Tue, 21 Jun 2016 18:27:31 -0400 Subject: [PATCH] Add simple c# GetContacts api call sample --- C-Sharp/GetContacts.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 C-Sharp/GetContacts.cs diff --git a/C-Sharp/GetContacts.cs b/C-Sharp/GetContacts.cs new file mode 100644 index 0000000..877cf07 --- /dev/null +++ b/C-Sharp/GetContacts.cs @@ -0,0 +1,35 @@ +using System; +using System.Net; +using System.Text; +using System.IO; + +class Program +{ + static void Main() + { + string fdDomain = "YOUR_DOMAIN"; // your freshdesk domain + string apiKey = "YOUR_API_KEY"; + string apiPath = "/api/v2/contacts"; // API path + string responseBody = String.Empty; + HttpWebRequest request =(HttpWebRequest)WebRequest.Create("https://" + fdDomain + ".freshdesk.com" + apiPath); + request.ContentType = "application/json"; + request.Method = "GET"; + string authInfo = apiKey + ":X"; // It could be your username:password also. + authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); + request.Headers["Authorization"] ="Basic "+authInfo; + + Console.WriteLine("Submitting Request"); + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + { + Stream dataStream = response.GetResponseStream(); + StreamReader reader = new StreamReader(dataStream); + responseBody = reader.ReadToEnd(); + reader.Close(); + dataStream.Close(); + //return status code + Console.WriteLine("Status Code: {1} {0}", ((HttpWebResponse)response).StatusCode, (int)((HttpWebResponse)response).StatusCode); + } + Console.Out.WriteLine(responseBody); + + } +} \ No newline at end of file