.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
- 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 | BeginLiveActivity | POST /apps/{app_id}/live_activities/{activity_id}/token | Start Live Activity |
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 | CreateSubscription | POST /apps/{app_id}/users/by/{alias_label}/{alias_id}/subscriptions | |
DefaultApi | CreateUser | POST /apps/{app_id}/users | |
DefaultApi | DeleteAlias | DELETE /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity/{alias_label_to_delete} | |
DefaultApi | DeletePlayer | DELETE /players/{player_id} | Delete a user record |
DefaultApi | DeleteSegments | DELETE /apps/{app_id}/segments/{segment_id} | Delete Segments |
DefaultApi | DeleteSubscription | DELETE /apps/{app_id}/subscriptions/{subscription_id} | |
DefaultApi | DeleteUser | DELETE /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
DefaultApi | EndLiveActivity | DELETE /apps/{app_id}/live_activities/{activity_id}/token/{subscription_id} | Stop Live Activity |
DefaultApi | ExportPlayers | POST /players/csv_export?app_id={app_id} | CSV export |
DefaultApi | FetchAliases | GET /apps/{app_id}/subscriptions/{subscription_id}/user/identity | |
DefaultApi | FetchUser | GET /apps/{app_id}/users/by/{alias_label}/{alias_id} | |
DefaultApi | FetchUserIdentity | GET /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity | |
DefaultApi | GetApp | GET /apps/{app_id} | View an app |
DefaultApi | GetApps | GET /apps | View apps |
DefaultApi | GetEligibleIams | GET /apps/{app_id}/subscriptions/{subscription_id}/iams | |
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 | IdentifyUserByAlias | PATCH /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity | |
DefaultApi | IdentifyUserBySubscriptionId | PATCH /apps/{app_id}/subscriptions/{subscription_id}/user/identity | |
DefaultApi | TransferSubscription | PATCH /apps/{app_id}/subscriptions/{subscription_id}/owner | |
DefaultApi | UpdateApp | PUT /apps/{app_id} | Update an app |
DefaultApi | UpdateLiveActivity | POST /apps/{app_id}/live_activities/{activity_id}/notifications | Update a Live Activity via Push |
DefaultApi | UpdatePlayer | PUT /players/{player_id} | Edit device |
DefaultApi | UpdatePlayerTags | PUT /apps/{app_id}/users/{external_user_id} | Edit tags with external user id |
DefaultApi | UpdateSubscription | PATCH /apps/{app_id}/subscriptions/{subscription_id} | |
DefaultApi | UpdateUser | PATCH /apps/{app_id}/users/by/{alias_label}/{alias_id} |
Documentation for Models
- Model.App
- Model.BadRequestError
- Model.BasicNotification
- Model.BasicNotificationAllOf
- Model.BasicNotificationAllOfAndroidBackgroundLayout
- Model.BeginLiveActivityRequest
- Model.Button
- Model.CancelNotificationSuccessResponse
- Model.CreateNotificationSuccessResponse
- Model.CreatePlayerSuccessResponse
- Model.CreateSegmentConflictResponse
- Model.CreateSegmentSuccessResponse
- Model.CreateSubscriptionRequestBody
- Model.CreateUserConflictResponse
- Model.CreateUserConflictResponseErrorsInner
- Model.CreateUserConflictResponseErrorsItemsMeta
- Model.DeletePlayerNotFoundResponse
- Model.DeletePlayerSuccessResponse
- Model.DeleteSegmentNotFoundResponse
- Model.DeleteSegmentSuccessResponse
- Model.DeliveryData
- Model.ExportPlayersRequestBody
- Model.ExportPlayersSuccessResponse
- Model.Filter
- Model.FilterExpressions
- Model.GetNotificationRequestBody
- Model.IdentifyUserConflictResponse
- Model.IdentifyUserConflictResponseErrorsInner
- Model.InlineResponse200
- Model.InlineResponse2003
- Model.InlineResponse201
- Model.InlineResponse202
- Model.InvalidIdentifierError
- Model.Notification
- Model.Notification200Errors
- Model.NotificationAllOf
- Model.NotificationHistorySuccessResponse
- Model.NotificationSlice
- Model.NotificationTarget
- Model.NotificationWithMeta
- Model.NotificationWithMetaAllOf
- Model.Operator
- Model.OutcomeData
- Model.OutcomesData
- Model.PlatformDeliveryData
- Model.PlatformDeliveryDataEmailAllOf
- Model.PlatformDeliveryDataSmsAllOf
- Model.Player
- Model.PlayerNotificationTarget
- Model.PlayerNotificationTargetIncludeAliases
- Model.PlayerSlice
- Model.PropertiesDeltas
- Model.PropertiesObject
- Model.Purchase
- Model.Segment
- Model.SegmentNotificationTarget
- Model.StringMap
- Model.SubscriptionObject
- Model.TransferSubscriptionRequestBody
- Model.UpdateLiveActivityRequest
- Model.UpdateLiveActivitySuccessResponse
- Model.UpdatePlayerSuccessResponse
- Model.UpdatePlayerTagsRequestBody
- Model.UpdatePlayerTagsSuccessResponse
- Model.UpdateSubscriptionRequestBody
- Model.UpdateUserRequest
- Model.User
- Model.UserIdentityRequestBody
- Model.UserIdentityResponse
- Model.UserSubscriptionOptions
Updated 2 months ago