You are using an unsupported browser. Please update your browser to the latest version on or before July 31, 2020.
close
You are viewing the article in preview mode. It is not live at the moment.
Home > HappyFox Help Desk > Account Configuration > Developers > API > HOWTO: Create a ticket using HappyFox API and C#
HOWTO: Create a ticket using HappyFox API and C#
print icon

Please find the below code to create a ticket using HappyFox API and C#.

 

Important Note: If the category you are creating the ticket in contains mandatory custom fields, please make sure to add them to the list of values in the postData below.

 

void CreateTicketUsingHTTPPost()

        {

            string subject = "TEST test ticket from api from .NET";

            string text = "test";

            string email = "john.smith@happyfox.com";

            string t_cf_1 = "2";

            string c_cf_1 = "2";

            string category = "1";

            string priority = "1";

            string user = "1";

            string user_name = "John Smith";

 

            string postData = "subject=" + subject;

            postData += ("&text=" + text);

            postData += ("&email=" + email);

            postData += ("&category=" + category);

            postData += ("&priority=" + priority);

            postData += ("&t-cf-1=" + t_cf_1);

            postData += ("&c-cf-1=" + c_cf_1);

            postData += ("&name=" + user_name);

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

 

            // Prepare web request...

            HttpWebRequest myRequest =

              (HttpWebRequest)WebRequest.Create("http://<youripaddress>/api/1.0/xml/tickets/");

            myRequest.Credentials = new NetworkCredential("<YourAuthKey>", "<YourSecret>");

            myRequest.Method = "POST";

            myRequest.ContentType = "application/x-www-form-urlencoded";

            myRequest.ContentLength = byteArray.Length;

            Stream dataStream;

            dataStream = myRequest.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);

            dataStream.Close();

 

            var response = (HttpWebResponse)myRequest.GetResponse();

        }

 

Feedback
8 out of 19 found this helpful

scroll to top icon