-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathupdateInstallation.ts
More file actions
44 lines (36 loc) · 1.65 KB
/
updateInstallation.ts
File metadata and controls
44 lines (36 loc) · 1.65 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
// 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
* @azsdk-weight 100
*/
import "dotenv/config";
import { createClientContext, updateInstallation } from "@azure/notification-hubs/api";
import type { JsonPatch } from "@azure/notification-hubs/models";
// 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(): Promise<void> {
const context = createClientContext(connectionString, hubName);
const updates: JsonPatch[] = [
{ 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);
});