Skip to content

OneSignal/onesignal-dotnet-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 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: 5.0.1
  • SDK version: 5.0.0-beta1
  • 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://api.onesignal.com";
            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://api.onesignal.com";
            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://api.onesignal.com

Class Method HTTP request Description
DefaultApi CancelNotification DELETE /notifications/{notification_id} Stop a scheduled or currently outgoing notification
DefaultApi CreateAlias PATCH /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApi CreateAliasBySubscription PATCH /apps/{app_id}/subscriptions/{subscription_id}/user/identity
DefaultApi CreateApp POST /apps Create an app
DefaultApi CreateNotification POST /notifications Create notification
DefaultApi CreateSegment POST /apps/{app_id}/segments Create Segment
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 DeleteSegment DELETE /apps/{app_id}/segments/{segment_id} Delete Segment
DefaultApi DeleteSubscription DELETE /apps/{app_id}/subscriptions/{subscription_id}
DefaultApi DeleteUser DELETE /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApi ExportEvents POST /notifications/{notification_id}/export_events?app_id={app_id} Export CSV of Events
DefaultApi ExportSubscriptions POST /players/csv_export?app_id={app_id} Export CSV of Subscriptions
DefaultApi GetAliases GET /apps/{app_id}/users/by/{alias_label}/{alias_id}/identity
DefaultApi GetAliasesBySubscription GET /apps/{app_id}/subscriptions/{subscription_id}/user/identity
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 GetSegments GET /apps/{app_id}/segments Get Segments
DefaultApi GetUser GET /apps/{app_id}/users/by/{alias_label}/{alias_id}
DefaultApi TransferSubscription PATCH /apps/{app_id}/subscriptions/{subscription_id}/owner
DefaultApi UnsubscribeEmailWithToken POST /apps/{app_id}/notifications/{notification_id}/unsubscribe Unsubscribe with token
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 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

rest_api_key

  • Type: Bearer Authentication

user_auth_key

  • Type: Bearer Authentication