Skip to content

OneSignal/onesignal-dotnet-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OneSignalApi - the C# library for the OneSignal

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

  • API version: 1.2.2
  • SDK version: 2.0.2
  • Build package: org.openapitools.codegen.languages.CSharpNetCoreClientCodegen For more information, please visit https://onesignal.com

Frameworks supported

  • .NET Core >=1.0
  • .NET Framework >=4.6
  • Mono/Xamarin >=vNext

Dependencies

The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:

Install-Package RestSharp
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations

NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742. NOTE: RestSharp for .Net Core creates a new socket for each api call, which can lead to a socket exhaustion problem. See RestSharp#1406.

Installation

Generate the DLL using your preferred tool (e.g. dotnet build)

Then include the DLL (under the bin folder) in the C# project, and use the namespaces:

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

Usage

To use the API client with a HTTP proxy, setup a System.Net.WebProxy

Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;

Getting Started

using System.Collections.Generic;
using System.Diagnostics;
using OneSignalApi.Api;
using OneSignalApi.Client;
using OneSignalApi.Model;

namespace Example
{
    public class Example
    {
        public static void Main()
        {
            // Configure configuration 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 = "USER_AUTH_KEY";
            
            var userInstance = new DefaultApi(userConfig);

            try
            {
                // Create a new app
                var app = new App(name: "Sample App");
                var result = userInstance.CreateApp(app);
                Debug.WriteLine(result);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling DefaultApi.CreateApp: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }


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

            var appId = "appId_example";  // string | 
            var notificationId = "notificationId_example";  // string | 
            try
            {
                // Stop a scheduled or currently outgoing notification
                var result = appInstance.CancelNotification(appId, notificationId);
                Debug.WriteLine(result);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling DefaultApi.CancelNotification: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }
        }
    }
}

Documentation for API Endpoints

All URIs are relative to https://onesignal.com/api/v1

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 ExportEvents POST /notifications/{notification_id}/export_events?app_id={app_id} Export CSV of Events
DefaultApi ExportPlayers POST /players/csv_export?app_id={app_id} Export CSV of Players
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

Documentation for Authorization

app_key

  • Type: Bearer Authentication

user_key

  • Type: Bearer Authentication