Skip to content

Instantly share code, notes, and snippets.

@subwiz
Created September 16, 2014 06:23
Show Gist options
  • Save subwiz/dff5daccce97c57958ec to your computer and use it in GitHub Desktop.
Save subwiz/dff5daccce97c57958ec to your computer and use it in GitHub Desktop.
C# Example for Creating Freshdesk Ticket With Attachment
using System;
using System.IO;
using System.Net.Http;
namespace HttpClientFDApi
{
class FreshdeskTicketAttachmentApi
{
static void Main(string[] args)
{
var credentials = new NetworkCredential("API_KEY", "X");
var handler = new HttpClientHandler { Credentials = credentials };
var client = new HttpClient(handler);
var content = new MultipartFormDataContent();
// Title, description and email:
content.Add(new StringContent("example@example.com"), "helpdesk_ticket[email]");
content.Add(new StringContent("Ticket Title"), "helpdesk_ticket[subject]");
content.Add(new StringContent("Ticket description."), "helpdesk_ticket[description]");
// Attachments:
content.Add(new StreamContent(File.Open("Image1.png", FileMode.Open)),
"helpdesk_ticket[attachments][][resource]", "Image1.png");
content.Add(new StreamContent(File.Open("Image2.png", FileMode.Open)),
"helpdesk_ticket[attachments][][resource]", "Image2.png");
var result = client.PostAsync("https://DOMAIN.freshdesk.com/helpdesk/tickets.json", content);
Console.WriteLine(result.Result.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment