Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Every SDK requires authentication via API keys. Two key types are available:
> **Warning:** Store your API keys in environment variables or a secrets manager. Never commit them to source control.

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

restAuth := context.WithValue(
context.Background(),
Expand All @@ -42,14 +42,14 @@ apiClient := onesignal.NewAPIClient(onesignal.NewConfiguration())

```go
notification := *onesignal.NewNotification("YOUR_APP_ID")
notification.SetContents(onesignal.StringMap{En: onesignal.PtrString("Hello from OneSignal!")})
notification.SetHeadings(onesignal.StringMap{En: onesignal.PtrString("Push Notification")})
notification.SetContents(onesignal.LanguageStringMap{En: onesignal.PtrString("Hello from OneSignal!")})
notification.SetHeadings(onesignal.LanguageStringMap{En: onesignal.PtrString("Push Notification")})
notification.SetIncludedSegments([]string{"Subscribed Users"})

response, _, err := apiClient.DefaultApi
.CreateNotification(orgAuth)
.Notification(notification)
.Execute()
response, _, err := apiClient.DefaultApi.
CreateNotification(orgAuth).
Notification(notification).
Execute()

if err != nil {
log.Fatal(err)
Expand All @@ -64,27 +64,27 @@ notification := *onesignal.NewNotification("YOUR_APP_ID")
notification.SetEmailSubject("Important Update")
notification.SetEmailBody("<h1>Hello!</h1><p>This is an HTML email.</p>")
notification.SetIncludedSegments([]string{"Subscribed Users"})
notification.SetChannelForExternalUserIds("email")
notification.SetTargetChannel("email")

response, _, err := apiClient.DefaultApi
.CreateNotification(orgAuth)
.Notification(notification)
.Execute()
response, _, err := apiClient.DefaultApi.
CreateNotification(orgAuth).
Notification(notification).
Execute()
```

## Send an SMS

```go
notification := *onesignal.NewNotification("YOUR_APP_ID")
notification.SetContents(onesignal.StringMap{En: onesignal.PtrString("Your SMS message content here")})
notification.SetContents(onesignal.LanguageStringMap{En: onesignal.PtrString("Your SMS message content here")})
notification.SetIncludedSegments([]string{"Subscribed Users"})
notification.SetChannelForExternalUserIds("sms")
notification.SetTargetChannel("sms")
notification.SetSmsFrom("+15551234567")

response, _, err := apiClient.DefaultApi
.CreateNotification(orgAuth)
.Notification(notification)
.Execute()
response, _, err := apiClient.DefaultApi.
CreateNotification(orgAuth).
Notification(notification).
Execute()
```

## Full API reference
Expand Down
Loading