Skip to main content

Hi there,


I have been trying to create a ticket that will have custom fields and file attachments with C#. 


I used the example provided from below link:

https://github.com/freshdesk/fresh-samples/blob/master/C-Sharp/CreateTicketWithAttachment.cs


However, the example doesn't show me how to convert customs fields to a correct format. so I have been getting the follow data mismatch error:

{"description":"Validation failed","errors"::{"field":"custom_fields","message":"Value set is of type String.It should be a/an key/value pair","code":"datatype_mismatch"}]}


Please see below code implementation and would be much appreciated if someone can let me know what I have done wrong:


 using (var rs = request.GetRequestStream())

 {

writeBoundaryBytes(rs, boundary, false);

writeContentDispositionFormDataHeader(rs, "custom_fields");

writeCustomerField(rs);

}


private void writeCustomerField(Stream o)

        {

            List<KeyValuePair<string, string>> kvpList = new List<KeyValuePair<string, string>>()

            {

                new KeyValuePair<string, string>("cf_system", "Email Request"),

            };

 

            BinaryFormatter bf = new BinaryFormatter();

            using (MemoryStream ms = new MemoryStream())

            {

                bf.Serialize(ms, kvpList);

                bytei] result = ms.ToArray();

                o.Write(result, 0, result.Length);

            }

        }