.NET Client SDK

The OneSignal .NET API Library allows for your backend .NET application to integrate with OneSignal for backend events, data, and more.

🚧

Backend SDKs in User Model Beta

You still can try using new User Model endpoints, we advise customers to not use these SDKs in production.

Installation

Install using Visual Studio

  1. In Solution Explore, right-click the References or a project and select Manage Nuget Packages...
  2. On the Browse tab Search for OneSignalApi. Select the OneSignalApi package from the list, then click Install.

Install using the Package Manager Console

  1. Open the project/solution in Visual Studio, and open the console using the Tools > NuGet Package Manager > Package Manager Console command.
  2. Run the install command
Install-Package OneSignalApi

Install using the dotnet CLI

  1. Open a command line and switch to the directory that contains your project file.
  2. Use the following command to install the OneSignalApi package to that project.
dotnet add package OneSignalApi

Usage

OneSignal has two authentication contexts, a separate client instance should be used for each context (see https://documentation.onesignal.com/reference to determine which endpoints require which authentication type)

  • AppAuth
  • UserAuth

AppAuth Example

var appConfig = new Configuration();
appConfig.BasePath = "https://onesignal.com/api/v1";
appConfig.AccessToken = "REST_API_KEY";
            
var appInstance = new DefaultApi(appConfig);

UserAuth Example

var appConfig = new Configuration();
appConfig.BasePath = "https://onesignal.com/api/v1";
appConfig.AccessToken = "USER_AUTH_KEY";
            
var appInstance = new DefaultApi(appConfig);

Advanced Example: Creating a brand new app

If creating a new app via the client, the response will return the app's API key via the basic_auth_key response parameter. You can then use this to modify your configuration object and create a new client that will ahve both user-level and app-level authentication set up.

// Configure with user_key Bearer token for authorization to access endpoints
// that require the OneSignal User Auth Key.
var userConfig = new Configuration();
userConfig.BasePath = "https://onesignal.com/api/v1";
userConfig.AccessToken = "YOUR_USER_AUTH_KEY";
var userInstance = new DefaultApi(userConfig);

// Create a new OneSignal application
var newApp = new App(name: "Sample App");
var newAppResult = await userInstance.CreateAppAsync(newApp);

// Configure a new API instance with app_key Bearer token for authorization to
// access endpoints that require the OneSignal App Auth Key.
var appConfig = new Configuration();
appConfig.BasePath = "https://onesignal.com/api/v1";
appConfig.AccessToken = newAppResult.BasicAuthKey;
var appInstance = new DefaultApi(appConfig);

// As an example, create a new player within the application just created
var player = new Player(appId: newAppResult.Id)
    {
        Identifier = "<A_DEVICE_IDENTIFIER>",
        DeviceType = 1
    };
await appInstance.CreatePlayerAsync(player);

API Reference

All URIs are relative to https://onesignal.com/api/v1. Each method has a synchronous version and an asynchronous version. The asynchronous versions will have Async appended to the method name.

ClassMethodHTTP requestDescription
DefaultApiBeginLiveActivityPOST /apps/{app_id}/live_activities/{activity_id}/tokenStart Live Activity
DefaultApiCancelNotificationDELETE /notifications/{notification_id}Stop a scheduled or currently outgoing notification
DefaultApiCreateAppPOST /appsCreate an app
DefaultApiCreateNotificationPOST /notificationsCreate notification
DefaultApiCreatePlayerPOST /playersAdd a device
DefaultApiCreateSegmentsPOST /apps/{app_id}/segmentsCreate Segments
DefaultApiCreateSubscriptionPOST /apps/{app_id}/users/by/{alias_label}/{alias_id}/subscriptions
DefaultApiCreateUserPOST /apps/{app_id}/users
DefaultApiDeleteAliasDELETE /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity/{alias_label_to_delete}
DefaultApiDeletePlayerDELETE /players/{player_id}Delete a user record
DefaultApiDeleteSegmentsDELETE /apps/{app_id}/segments/{segment_id}Delete Segments
DefaultApiDeleteSubscriptionDELETE /apps/{app_id}/subscriptions/{subscription_id}
DefaultApiDeleteUserDELETE /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApiEndLiveActivityDELETE /apps/{app_id}/live_activities/{activity_id}/token/{subscription_id}Stop Live Activity
DefaultApiExportPlayersPOST /players/csv_export?app_id={app_id}CSV export
DefaultApiFetchAliasesGET /apps/{app_id}/subscriptions/{subscription_id}/user/identity
DefaultApiFetchUserGET /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApiFetchUserIdentityGET /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApiGetAppGET /apps/{app_id}View an app
DefaultApiGetAppsGET /appsView apps
DefaultApiGetEligibleIamsGET /apps/{app_id}/subscriptions/{subscription_id}/iams
DefaultApiGetNotificationGET /notifications/{notification_id}View notification
DefaultApiGetNotificationHistoryPOST /notifications/{notification_id}/historyNotification History
DefaultApiGetNotificationsGET /notificationsView notifications
DefaultApiGetOutcomesGET /apps/{app_id}/outcomesView Outcomes
DefaultApiGetPlayerGET /players/{player_id}View device
DefaultApiGetPlayersGET /playersView devices
DefaultApiIdentifyUserByAliasPATCH /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApiIdentifyUserBySubscriptionIdPATCH /apps/{app_id}/subscriptions/{subscription_id}/user/identity
DefaultApiTransferSubscriptionPATCH /apps/{app_id}/subscriptions/{subscription_id}/owner
DefaultApiUpdateAppPUT /apps/{app_id}Update an app
DefaultApiUpdateLiveActivityPOST /apps/{app_id}/live_activities/{activity_id}/notificationsUpdate a Live Activity via Push
DefaultApiUpdatePlayerPUT /players/{player_id}Edit device
DefaultApiUpdatePlayerTagsPUT /apps/{app_id}/users/{external_user_id}Edit tags with external user id
DefaultApiUpdateSubscriptionPATCH /apps/{app_id}/subscriptions/{subscription_id}
DefaultApiUpdateUserPATCH /apps/{app_id}/users/by/{alias_label}/{alias_id}

Documentation for Models