We are pleased to announce that the OneSignal .NET API Library is now available. This new .NET client supports developers using OneSignal by facilitating the integration of the OneSignal REST API with your backend events, data, and more. This release is part of our ongoing initiative to add server SDKs across various languages and technologies.

.NET is one of the most famous and widely used frameworks.  Developed by Microsoft and now open-source, the C#, F#, and (still breathing) Visual Basic languages are fully supported on a cross-platform environment atop Windows, MacOS and Linux.  The robust libraries and support found within the .NET ecosystem allow developers to easily build a wide variety of web, mobile, desktop, games, and IoT applications.

Getting Started

Installation

If you are using Visual Studio...

In Solution Explorer, right-click your project and select Manage Nuget Packages.

On the Browse tab, search for OneSignalApi. Select the OneSignalApi package from the list, then click Install.

If you are using the .NET CLI, in your command prompt switch to the directory that contains your project file then run this command:

dotnet add package OneSignalApi

Authorization

OneSignal has two authentication contexts: AppAuth which is used for API endpoints specific to your OneSignal application, and UserAuth which is used for API endpoints more general to your OneSignal user. The Rest API Reference identifies which endpoints require which authorization context.

When configuring the .NET library, the appropriate key should be set in AccessToken. How to generate and/or access these keys within the OneSignal Dashboard can be found in our keys and IDs documentation.

Example

Below is an example that demonstrates how simple it is to send a notification, in this case to all subscribed users, through the .NET API.

using OneSignalApi.Api;
using OneSignalApi.Client;
using OneSignalApi.Model;

// Configure the OneSignal Library
var appConfig = new Configuration();
appConfig.BasePath = "https://onesignal.com/api/v1";
appConfig.AccessToken = "<YOUR_APP_REST_API_KEY_HERE>";
var appInstance = new DefaultApi(appConfig);

// Create and send notification to all subscribed users
var notification = new Notification(appId: "<YOUR_APP_ID_HERE>")
{                
	Contents = new StringMap(en: "Hello World from .NET!"),
	IncludedSegments = new List<string> { "Subscribed Users" }
};
var response = await appInstance.CreateNotificationAsync(notification);

Console.WriteLine($"Notification created for {response.Recipients} recipients");

Reference

Visit our REST API Reference documentation for a complete list of our supported endpoints.

Visit our .NET API reference for a list of supported functions and view implementation examples for .NET.

Share Your Feedback

If you’ve had a chance to use our new .NET API library and have any feedback or suggestions you’d like to share, please reach out to us on the GitHub repository or our Discord server.

If you encounter any bugs or technical issues while using our new .NET library, we want to know so we can make things right. Please be sure to file a report on our GitHub repository.

If you’ve found the plugin helpful, we’d appreciate it if you left us a review on G2.