Introduction 

Hi everyone! I’m currently doing my internship where I got an opportunity to work with the Freshdesk API. As someone who’s just starting out, I wanted to share how I was able to fetch ticket details from Freshdesk using C# and display them in a simple .NET front-end. 
 
If you’re also new to APIs or .NET, I hope this blog gives you a basic idea of how to integrate an external service like Freshdesk into your own application.

What is Freshdesk? 

Freshdesk is a customer support platform that helps businesses manage their support tickets. It provides a REST API which allows us to interact with it programmatically—for example, to create or fetch support tickets. 

Goal of This Blog 

We’ll build a simple C# application that: 
– Connects to the Freshdesk API 
– Fetches the list of tickets 
– Displays them in a .NET Razor page 

Step 1: Set Up Your Freshdesk API Key 

1. Login to your Freshdesk account 
2. Go to your profile > API key 
3. Copy the API key—you’ll need it to authenticate your API calls 

Step 2: Create a .NET Web App (Razor Pages) 

You can use Visual Studio to create a new ASP.NET Core Web App (Razor Pages). 

Command: dotnet new webapp -n FreshdeskTicketViewer 

Step 3: Add a Model for Ticket Data 

Create a class called Ticket.cs: 

public class Ticket 
{ 
    public long id { get; set; } 
    public string subject { get; set; } 
    public string status { get; set; } 
    public string priority { get; set; } 
} 

Step 4: Create a Service to Call Freshdesk API 

Create a simple service to fetch ticket data. 

public class FreshdeskService 
{ 
    private readonly HttpClient _client; 
 
    public FreshdeskService() 
    { 
        _client = new HttpClient(); 
        var apiKey = "your_api_key"; // Replace with your actual API key 
        var base64Auth = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{apiKey}:X")); 
 
        _client.DefaultRequestHeaders.Authorization = 
            new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64Auth); 
    } 
 
    public async Task<List<Ticket>> GetTicketsAsync() 
    { 
        var response = await _client.GetAsync("https://yourdomain.freshdesk.com/api/v2/tickets"); 
        if (response.IsSuccessStatusCode) 
        { 
            var json = await response.Content.ReadAsStringAsync(); 
            return JsonConvert.DeserializeObject<List<Ticket>>(json); 
        } 
 
        return new List<Ticket>(); 
    } 
} 

Step 5: Display Tickets on Razor Page 

In Index.cshtml.cs: 

public class IndexModel : PageModel 
{ 
    public List<Ticket> Tickets { get; set; } = new(); 
 
    public async Task OnGetAsync() 
    { 
        var service = new FreshdeskService(); 
        Tickets = await service.GetTicketsAsync(); 
    } 
} 


In Index.cshtml: 

<h2>Freshdesk Tickets</h2> 
<table class="table"> 
    <thead> 
        <tr> 
            <th>ID</th> 
            <th>Subject</th> 
            <th>Status</th> 
            <th>Priority</th> 
        </tr> 
    </thead> 
    <tbody> 
        foreach (var ticket in Model.Tickets) 
        { 
            <tr> 
                <td>@ticket.id</td> 
                <td>@ticket.subject</td> 
                <td>@ticket.status</td> 
                <td>@ticket.priority</td> 
            </tr> 
        } 
    </tbody> 
</table> 

 

Key Takeaways

Next Steps

In the future, I’m planning to: 
– Add ticket filtering by status 
– Handle API errors more gracefully 
– Try using Blazor instead of Razor Pages 

Conclusion 

I hope this beginner-friendly walkthrough helps others like me who are new to integrating third-party APIs. Freshdesk’s API is well-documented, and combining it with .NET was a great learning experience. 
 
Feel free to connect if you have any questions or want to share your own experience! 

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.