Go Client SDK

The OneSignal Go client is a server OneSignal SDK for Golang. Integrate OneSignal with your 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

go get github.com/OneSignal/onesignal-go-api

Install the following dependencies:

go get golang.org/x/oauth2

Put the package under your project folder and add the following in import:

import "github.com/OneSignal/onesignal-go-api"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), onesignal.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), onesignal.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration.
An operation is uniquely identified by "{classname}Service.{nickname}" string.
Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), onesignal.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), onesignal.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

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

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

Documentation For Authorization

Use a OneSignal authentication context for each auth type:

  • AppAuth
  • UserAuth

app_key

  • Type: HTTP Bearer token authentication

Example

appAuth := context.WithValue(context.Background(), onesignal.AppAuth, "YOUR_API_KEY")

user_key

  • Type: HTTP Bearer token authentication

Example

userAuth := context.WithValue(context.Background(), onesignal.UserAuth, "USER_KEY_STRING")

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains
a number of utility functions to easily obtain pointers to values of basic types.
Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime