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
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
- App
- BadRequestError
- BasicNotification
- BasicNotificationAllOf
- BasicNotificationAllOfAndroidBackgroundLayout
- BeginLiveActivityRequest
- Button
- CancelNotificationSuccessResponse
- CreateNotificationSuccessResponse
- CreatePlayerSuccessResponse
- CreateSegmentConflictResponse
- CreateSegmentSuccessResponse
- CreateSubscriptionRequestBody
- CreateUserConflictResponse
- CreateUserConflictResponseErrorsInner
- CreateUserConflictResponseErrorsItemsMeta
- DeletePlayerNotFoundResponse
- DeletePlayerSuccessResponse
- DeleteSegmentNotFoundResponse
- DeleteSegmentSuccessResponse
- DeliveryData
- ExportPlayersRequestBody
- ExportPlayersSuccessResponse
- Filter
- FilterExpressions
- GetNotificationRequestBody
- IdentifyUserConflictResponse
- IdentifyUserConflictResponseErrorsInner
- InlineResponse200
- InlineResponse2003
- InlineResponse201
- InlineResponse202
- InvalidIdentifierError
- Notification
- Notification200Errors
- NotificationAllOf
- NotificationHistorySuccessResponse
- NotificationSlice
- NotificationTarget
- NotificationWithMeta
- NotificationWithMetaAllOf
- Operator
- OutcomeData
- OutcomesData
- PlatformDeliveryData
- PlatformDeliveryDataEmailAllOf
- PlatformDeliveryDataSmsAllOf
- Player
- PlayerNotificationTarget
- PlayerNotificationTargetIncludeAliases
- PlayerSlice
- PropertiesDeltas
- PropertiesObject
- Purchase
- Segment
- SegmentNotificationTarget
- StringMap
- SubscriptionObject
- TransferSubscriptionRequestBody
- UpdateLiveActivityRequest
- UpdateLiveActivitySuccessResponse
- UpdatePlayerSuccessResponse
- UpdatePlayerTagsRequestBody
- UpdatePlayerTagsSuccessResponse
- UpdateSubscriptionRequestBody
- UpdateUserRequest
- User
- UserIdentityRequestBody
- UserIdentityResponse
- UserSubscriptionOptions
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
Updated 2 months ago