Unable To Create A Freshdesk Ticket With Attachment Through Api

I am integrating Freshdesk Create a Ticket with Attachment Api using C# coding. I am getting an error.
error details:

{“description”:“Validation failed”,“errors”:[{“field”:“email\r\n”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”},{“field”:“subject\r\n”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”},{“field”:“description\r\n”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”},{“field”:“name\r\n”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”},{“field”:“status\r\n”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”},{“field”:“priority\r\n”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”}]}

Adding the C# code snippet that I used

Code :

    var client = new RestClient(freshdeskUrl);
    var request = new RestRequest("", Method.Post);

    request.AddHeader("Accept", "application/json");
    request.AddHeader("Content-Type", "multipart/form-data");
    request.AddHeader("Authorization", "Basic " + 
    Convert.ToBase64String(Encoding.Default.GetBytes(apiKey + ":X")));


    request.AddParameter("email", "example@example.com");
    request.AddParameter("subject", "Subject");
    request.AddParameter("description", "Description");
  

    request.AddFile("attachments[]", attachmentBytes, "Logs.txt", "text/plain");
var response = await client.ExecuteAsync(request);   

Can you please help me to resolve this issue.

Try changing the “Content-Type” from “application/json” to “multipart/form-data”.

Also, this url might be helpful:
https://github.com/freshworks/fresh-samples/blob/master/C-Sharp/CreateTicketWithAttachment.cs

Thanks for the response.
I tried by changing the “Content-Type” from “application/json” to “multipart/form-data”. but getting the same error.
I followed the code in url you shared. but the function used in the method are obsolete.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.