OneSignal / onesignal-go-api

The official OneSignal API client for Go
MIT License
11 stars 7 forks source link

[question]: Can not create notification #28

Closed duckhue01 closed 1 year ago

duckhue01 commented 1 year ago

How can we help?

I create a notification as following. I received a success message but I don't see any message on the dashboard. Do i miss any field?

package main

import (
    "context"
    "fmt"
    "os"

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

func main() {
    notification := *onesignal.NewNotification("app_id")
    notification.SetIncludeExternalUserIds([]string{"02d670b3-b7d9-4fcf-9535-9f51a2d21616"})

    notification.Contents.Set(&onesignal.StringMap{
        En:                   onesignal.PtrString("sasdasdasd"),
    })

    configuration := onesignal.NewConfiguration()

    apiClient := onesignal.NewAPIClient(configuration)

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

    resp, r, err := apiClient.DefaultApi.CreateNotification(appAuth).Notification(notification).Execute()

    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.CreateNotification``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    // response from `CreateNotification`: CreateNotificationSuccessResponse
    fmt.Fprintf(os.Stdout, "Response from `DefaultApi.CreateNotification`: %v\n", resp)
}

Code of Conduct