Created
December 7, 2011 21:25
-
-
Save skipjac/1444736 to your computer and use it in GitHub Desktop.
Zendesk delete ticket using C#
This file contains hidden or 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
| try | |
| { | |
| Int32 Start = 1042; | |
| Int32 End = 2715; | |
| for (Int32 i = Start; i <= End; i++) | |
| { | |
| //REST help sais request must be sent to http://helpdesk.zendesk.com. That's not the case. | |
| HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://tigabytes.zendesk.com/tickets/" + i + ".xml"); | |
| request.Credentials = new NetworkCredential("soporteadmin@tigabytes.com", "PASSWORD"); | |
| //If you comment last line, uncomment next. Basic Http authentication is supported in .Net these ways. | |
| //request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("soporteadmin@tigabytes.com:PASSWORd"))); | |
| request.Method = "DELETE"; | |
| request.ContentType = "application/json"; | |
| request.ContentLength = 0; | |
| request.KeepAlive = false; | |
| HttpWebResponse response = | |
| (HttpWebResponse)request.GetResponse(); | |
| Console.WriteLine("Delete ticket " + i + " " + | |
| response.StatusCode.ToString() + " (" + response.StatusDescription + ")"); | |
| //Ignoring this will timeout at third request | |
| response.Close(); | |
| } | |
| } | |
| catch (WebException webex) | |
| { | |
| //Here go exceptions : 401 (unauthorized), 404 (not found, | |
| when trying to delete a ticket that does not exist), and so on | |
| webex.ToString(); | |
| } | |
| catch (Exception ex) | |
| { | |
| //Other Excepcions | |
| ex.ToString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment