Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create notification with include_aliases failed #38

Open
1 task done
kienvtqhi opened this issue Nov 8, 2023 · 4 comments
Open
1 task done

Create notification with include_aliases failed #38

kienvtqhi opened this issue Nov 8, 2023 · 4 comments

Comments

@kienvtqhi
Copy link

kienvtqhi commented Nov 8, 2023

How can we help?

Hello,

I am using create notification API with included_aliases to send the notification to the specified user by external_id.

aliasExternalIds := &onesignal.PlayerNotificationTargetIncludeAliases{
		AdditionalProperties: map[string]interface{}{
			"external_id": []string{receiverId},
		},
	}

notification.IncludeAliases = *onesignal.NewNullablePlayerNotificationTargetIncludeAliases(aliasExternalIds)

notification.IncludeExternalUserIds = []string{receiverId}

	targeChannel := "push"
	notification.TargetChannel = &targeChannel
	// notification.IncludedSegments = []string{"Total Subscriptions"}

	var iosBadgeCount *int32 = new(int32)
	*iosBadgeCount = 1
	notification.IosBadgeCount = *onesignal.NewNullableInt32(iosBadgeCount)

	iosBadgeType := "Increase"
	notification.IosBadgeType = *onesignal.NewNullableString(&iosBadgeType)

	appAuth := context.WithValue(context.Background(), onesignal.AppAuth, nd.oneSignalConfig.RestApiKey)

	successResponse, _, err := nd.oneSignalApiClient.DefaultApi.CreateNotification(appAuth).Notification(notification).Execute()

But it is failed. It return the invalid_aliases.

{
    "id": "b15ba6e5-2223-49d6-9eda-684b9051f5a8",
    "external_id": null,
    "errors": {
        "invalid_aliases": {
            "external_id": [
                "bnudasdfRUt4yUJh0912E63tzIXPsxq1"
            ]
        }
    }
}

What's wrong?
Please help me to fix it.

Thank you so much!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jasperkuperus
Copy link

Same issue here. I'm trying to migrate from device-centric to the user-centric model. From the app everything works. Now I'm writing a migration script that loops over all subscription IDs of a user. For the first subscription, it gets the onesignal_id using GET https://onesignal.com/api/v1/apps/${onesignalAppId}/subscriptions/${subscriptionId}/user/identity.

Then it creates an alias by doing PATCH https://onesignal.com/api/v1/apps/${onesignalAppId}/users/by/onesignal_id/${oneSignalId}/identity.

For the rest of the subscriptions connected to a user, I transfer the subscriptions using PATCH https://onesignal.com/api/v1/apps/${onesignalAppId}/subscriptions/${subscriptionId}/owner.

I've tested this approach manually and it seems to work. I have now ran my script on 1 user and when I get that user by external_id, it properly shows me all subscriptions connected to that user.

However, when I now try to send a notification, I get this:

{"id":"","errors":{"invalid_aliases":{"external_id":["3cc7a2ba-91ea-4b18-93fc-c2123e458c6e","3cc7a2ba-91ea-4b18-93fc-c2123e458c6e","3cc7a2ba-91ea-4b18-93fc-c2123e458c6e","3cc7a2ba-91ea-4b18-93fc-c2123e458c6e","3cc7a2ba-91ea-4b18-93fc-c2123e458c6e"]}}}

Thoughts, @emawby?

@malikmajai
Copy link

It happens when notifications permission is not enabled by user on device.

@jasperkuperus
Copy link

@malikmajai I could see the logic there, but sending a notification to that external_id then fails as a whole. Even the linked subscriptions that do have permissions enabled don't get the notification. If you're sending a notification to 3 devices, where 1 device is not properly configured, the other 2 should still get the notification. Otherwise the whole user-centric model doesn't have any value.

@iuriandreazza
Copy link

This is still happening for today, do anyone has a workaround on this or should we just send to each individual user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants