-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathupdateRegistration.js
More file actions
49 lines (38 loc) · 1.55 KB
/
updateRegistration.js
File metadata and controls
49 lines (38 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how the updateRegistration() method can be used to update a device registration using
* Notification Hubs. This sample shows using the getRegistrationById() method to retrieve an existing registration.
*
* See https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-registration-management
* to learn about registrations.
*
*
* @summary Demonstrates how to update an installation using Azure Notification Hubs
*/
require("dotenv/config");
const {
createClientContext,
getRegistration,
updateRegistration,
} = require("@azure/notification-hubs/api");
// Define connection string and hub name
const connectionString = process.env.NOTIFICATIONHUBS_CONNECTION_STRING || "<connection string>";
const hubName = process.env.NOTIFICATION_HUB_NAME || "<hub name>";
// Define an existing Registration ID.
const registrationId = process.env.REGISTRATION_ID || "<registrationId>";
async function main() {
const context = createClientContext(connectionString, hubName);
const registration = await getRegistration(context, registrationId);
// Add some tags
if (!registration.tags) {
registration.tags = [];
}
registration.tags.push("likes_sports");
const registrationResponse = await updateRegistration(context, registration);
console.log(`Registration ID: ${registrationResponse.registrationId}`);
}
main().catch((err) => {
console.log("updateRegistration Sample: Error occurred: ", err);
process.exit(1);
});