How to prevent duplicate registrations when using REST API https://video2.skills-academy.com/en-us/rest/api/notificationhubs/create-overwrite-installation

Augusto Piva 15 Reputation points
2023-11-23T21:01:06.9366667+00:00

Hi everyone,

I'm reaching community as I'm experiencing some weird duplicate registrations when using the REST API https://video2.skills-academy.com/en-us/rest/api/notificationhubs/create-overwrite-installation

Let's say I create a an installation with a given token, user Id and installation Id by doing the call;

User's image

This suppose to create one installation but then what I get is two registration with the following details:

User's image

You can clearly see two registrations when calling by using https://video2.skills-academy.com/en-us/rest/api/notificationhubs/read-all-registrations-tag, with tag $InstallationId:{4307B40E-983B-4231-BD55-2136756629F4}.

The main difference is that in one of them I have the template I'm using. The other one doesn't have it.

Why is that? Is it normal? or is something that shouldn't happen?

If so, How should I prevent this?

Hope I'm clear on how I'm explaining this to all.

Thanks!

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
319 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 21,506 Reputation points
    2023-11-29T10:59:51.92+00:00

    @Augusto Piva Thanks for reaching here! It seems like you are experiencing duplicate registrations when creating an installation using the REST API. This can happen if the installation already exists with the same installation ID and PNS handle. In this case, the existing installation will be overwritten with the new one. However, if the installation does not exist, a new installation will be created.

    Regarding the two registrations you are seeing, one with the template and the other without it, it is possible that the installation was created twice with the same installation ID and PNS handle. This can happen if the installation creation request was sent twice or if there was a delay in the response from the server, causing the client to send the request again.

    To prevent this from happening, you can try to implement a unique identifier for each installation, such as a GUID, and use it as the installation ID. This will ensure that each installation is unique and prevent duplicates from being created.

    Additionally, you can also check if the installation already exists before creating a new one by using the Read Installation API. If the installation already exists, you can update it instead of creating a new one.

    See- https://video2.skills-academy.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management

    I hope this helps! Let me know if you have any further questions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.