-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathupdateInstallation.js
More file actions
41 lines (34 loc) · 1.55 KB
/
updateInstallation.js
File metadata and controls
41 lines (34 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how the updateInstallation() method can be used to update an installation using
* the JSON Patch (https://datatracker.ietf.org/doc/html/rfc6902). This sends discrete updates using the standard
* operation type, path and value if necessary.
*
* See https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-registration-management
* to learn about installations.
*
*
* @summary Demonstrates how to update an installation using Azure Notification Hubs
*/
require("dotenv/config");
const { createClientContext, updateInstallation } = 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 Installation ID.
const installationId = process.env.INSTALLATION_ID || "<installation id>";
async function main() {
const context = createClientContext(connectionString, hubName);
const updates = [
{ op: "add", path: "/tags", value: "likes_baseball" },
{ op: "add", path: "/userId", value: "bob@contoso.com" },
];
const result = await updateInstallation(context, installationId, updates);
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
}
main().catch((err) => {
console.log("updateInstallation Sample: Error occurred: ", err);
process.exit(1);
});