Back

Step by Step Guide to Building a Bonjoro API Integration in C#

Aug 15, 20246 minute read

Hey there, fellow developer! Ready to supercharge your app with some personalized video magic? Let's dive into building a Bonjoro API integration in C#. Trust me, it's easier than you might think, and by the end of this guide, you'll be sending custom videos like a pro!

Introduction

Bonjoro's API is a powerful tool that lets you automate personalized video creation and delivery. Whether you're looking to welcome new users, follow up with leads, or just add a personal touch to your app, this integration is your ticket to video marketing nirvana.

Prerequisites

Before we jump in, make sure you've got:

  • Visual Studio or your favorite C# IDE
  • .NET Core 3.1 or later
  • A Bonjoro account and API key (grab one from your Bonjoro dashboard if you haven't already)

Setting up the project

Let's get the boring stuff out of the way:

  1. Fire up Visual Studio and create a new C# project.
  2. Install the following NuGet packages:
    Install-Package Newtonsoft.Json
    Install-Package RestSharp
    

Authentication

Alright, let's get you authenticated:

using RestSharp; using RestSharp.Authenticators; var client = new RestClient("https://api.bonjoro.com/v2"); client.Authenticator = new JwtAuthenticator("YOUR_API_KEY");

Replace YOUR_API_KEY with your actual Bonjoro API key. Easy peasy!

Core API Endpoints

Now for the fun part. Let's implement some key Bonjoro features:

Sending a video

public async Task<IRestResponse> SendVideo(string recipientEmail, string message) { var request = new RestRequest("videos", Method.POST); request.AddJsonBody(new { recipient_email = recipientEmail, message = message }); return await client.ExecuteAsync(request); }

Retrieving video status

public async Task<IRestResponse> GetVideoStatus(string videoId) { var request = new RestRequest($"videos/{videoId}", Method.GET); return await client.ExecuteAsync(request); }

Managing recipients

public async Task<IRestResponse> AddRecipient(string email, string name) { var request = new RestRequest("recipients", Method.POST); request.AddJsonBody(new { email = email, name = name }); return await client.ExecuteAsync(request); }

Error Handling

Don't forget to wrap your API calls in try-catch blocks:

try { var response = await SendVideo("[email protected]", "Welcome aboard!"); if (response.IsSuccessful) { // Handle success } else { // Handle API errors Console.WriteLine($"API Error: {response.Content}"); } } catch (Exception ex) { // Handle exceptions Console.WriteLine($"Exception: {ex.Message}"); }

Example Use Cases

Here's a quick example of sending a welcome video to a new user:

public async Task WelcomeNewUser(string userEmail, string userName) { await AddRecipient(userEmail, userName); await SendVideo(userEmail, $"Welcome to our app, {userName}! We're thrilled to have you on board."); }

Testing the Integration

Don't forget to test your integration! Here's a simple unit test to get you started:

[Test] public async Task SendVideo_ShouldReturnSuccessStatus() { var response = await SendVideo("[email protected]", "Test message"); Assert.IsTrue(response.IsSuccessful); }

Best Practices

  • Respect Bonjoro's rate limits to keep your integration running smoothly.
  • Never hardcode your API key. Use environment variables or a secure configuration manager.

Conclusion

And there you have it! You've just built a Bonjoro API integration in C#. With this foundation, you can now send personalized videos, track their status, and manage recipients all from your C# application. The possibilities are endless!

Remember, this is just the beginning. Explore the Bonjoro API docs to discover more features and really make your integration shine.

Happy coding, and may your videos always be engaging!

Resources