.NET Client SDK
The OneSignal .NET API Library allows for your backend .NET application to integrate with OneSignal for backend events, data, and more.
Installation
Install using Visual Studio
- In Solution Explore, right-click the References or a project and select Manage Nuget Packages...
- On the Browse tab Search for
OneSignalApi
. Select the OneSignalApi package from the list, then click Install.
Install using the Package Manager Console
- Open the project/solution in Visual Studio, and open the console using the Tools > NuGet Package Manager > Package Manager Console command.
- Run the install command
Install-Package OneSignalApi
Install using the dotnet CLI
- Open a command line and switch to the directory that contains your project file.
- 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.
Class | Method | HTTP request | Description |
---|---|---|---|
DefaultApi | CancelNotification | DELETE /notifications/{notification_id} | Stop a scheduled or currently outgoing notification |
DefaultApi | CreateApp | POST /apps | Create an app |
DefaultApi | CreateNotification | POST /notifications | Create notification |
DefaultApi | CreatePlayer | POST /players | Add a device |
DefaultApi | CreateSegments | POST /apps/{app_id}/segments | Create Segments |
DefaultApi | DeletePlayer | DELETE /players/{player_id} | Delete a user record |
DefaultApi | DeleteSegments | DELETE /apps/{app_id}/segments/{segment_id} | Delete Segments |
DefaultApi | ExportPlayers | POST /players/csv_export?app_id={app_id} | CSV export |
DefaultApi | GetApp | GET /apps/{app_id} | View an app |
DefaultApi | GetApps | GET /apps | View apps |
DefaultApi | GetNotification | GET /notifications/{notification_id} | View notification |
DefaultApi | GetNotificationHistory | POST /notifications/{notification_id}/history | Notification History |
DefaultApi | GetNotifications | GET /notifications | View notifications |
DefaultApi | GetOutcomes | GET /apps/{app_id}/outcomes | View Outcomes |
DefaultApi | GetPlayer | GET /players/{player_id} | View device |
DefaultApi | GetPlayers | GET /players | View devices |
DefaultApi | UpdateApp | PUT /apps/{app_id} | Update an app |
DefaultApi | UpdatePlayer | PUT /players/{player_id} | Edit device |
DefaultApi | UpdatePlayerTags | PUT /apps/{app_id}/users/{external_user_id} | Edit tags with external user id |
Updated over 2 years ago