Created
March 29, 2018 10:55
-
-
Save pedroadaodev/a80078a4778821b6c9abe7c6f4311c61 to your computer and use it in GitHub Desktop.
FreshDesk create new Ticket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ADD FOR latest SSL standards | |
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; | |
// IGNORE SSL certification errors | |
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; | |
var url = "https://my.freshdesk.com/"; | |
var username = ConfigurationManager.AppSettings["Freshdesk.AppUsername"]; | |
var key = ConfigurationManager.AppSettings["Freshdesk.AppKey"]; | |
HttpClient client = new HttpClient(); | |
client.BaseAddress = new Uri(url); | |
client.DefaultRequestHeaders.Accept.Clear(); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
var byteArray = Encoding.ASCII.GetBytes($"{username}:{key}"); | |
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); | |
HttpResponseMessage response = client.PostAsJsonAsync("api/v2/tickets", model).Result; | |
if (response.StatusCode == HttpStatusCode.Created) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment