POST https://management.azure.com/subscriptions/daefabc0-95b4-48b3-b645-8a753a63c4fa/resourceGroups/resourceGroup1/providers/Microsoft.DesktopVirtualization/hostPools/hostPool1/sessionHosts/sessionHost1.microsoft.com/userSessions/1/sendMessage?api-version=2024-04-03
{
"messageTitle": "title",
"messageBody": "body"
}
import com.azure.resourcemanager.desktopvirtualization.models.SendMessage;
/**
* Samples for UserSessions SendMessage.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/stable/2024-04-03/examples/
* UserSession_SendMessage_Post.json
*/
/**
* Sample code: UserSession_SendMessage_Post.
*
* @param manager Entry point to DesktopVirtualizationManager.
*/
public static void userSessionSendMessagePost(
com.azure.resourcemanager.desktopvirtualization.DesktopVirtualizationManager manager) {
manager.userSessions().sendMessageWithResponse("resourceGroup1", "hostPool1", "sessionHost1.microsoft.com", "1",
new SendMessage().withMessageTitle("title").withMessageBody("body"), com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.desktopvirtualization import DesktopVirtualizationMgmtClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-desktopvirtualization
# USAGE
python user_session_send_message_post.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = DesktopVirtualizationMgmtClient(
credential=DefaultAzureCredential(),
subscription_id="daefabc0-95b4-48b3-b645-8a753a63c4fa",
)
client.user_sessions.send_message(
resource_group_name="resourceGroup1",
host_pool_name="hostPool1",
session_host_name="sessionHost1.microsoft.com",
user_session_id="1",
)
# x-ms-original-file: specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/stable/2024-04-03/examples/UserSession_SendMessage_Post.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armdesktopvirtualization_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/desktopvirtualization/armdesktopvirtualization/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/4883fa5dbf6f2c9093fac8ce334547e9dfac68fa/specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/stable/2024-04-03/examples/UserSession_SendMessage_Post.json
func ExampleUserSessionsClient_SendMessage() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armdesktopvirtualization.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
_, err = clientFactory.NewUserSessionsClient().SendMessage(ctx, "resourceGroup1", "hostPool1", "sessionHost1.microsoft.com", "1", &armdesktopvirtualization.UserSessionsClientSendMessageOptions{SendMessage: &armdesktopvirtualization.SendMessage{
MessageBody: to.Ptr("body"),
MessageTitle: to.Ptr("title"),
},
})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { DesktopVirtualizationAPIClient } = require("@azure/arm-desktopvirtualization");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Send a message to a user.
*
* @summary Send a message to a user.
* x-ms-original-file: specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/stable/2024-04-03/examples/UserSession_SendMessage_Post.json
*/
async function userSessionSendMessagePost() {
const subscriptionId =
process.env["DESKTOPVIRTUALIZATION_SUBSCRIPTION_ID"] || "daefabc0-95b4-48b3-b645-8a753a63c4fa";
const resourceGroupName = process.env["DESKTOPVIRTUALIZATION_RESOURCE_GROUP"] || "resourceGroup1";
const hostPoolName = "hostPool1";
const sessionHostName = "sessionHost1.microsoft.com";
const userSessionId = "1";
const sendMessage = {
messageBody: "body",
messageTitle: "title",
};
const options = { sendMessage };
const credential = new DefaultAzureCredential();
const client = new DesktopVirtualizationAPIClient(credential, subscriptionId);
const result = await client.userSessions.sendMessage(
resourceGroupName,
hostPoolName,
sessionHostName,
userSessionId,
options,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.DesktopVirtualization.Models;
using Azure.ResourceManager.DesktopVirtualization;
// Generated from example definition: specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/stable/2024-04-03/examples/UserSession_SendMessage_Post.json
// this example is just showing the usage of "UserSessions_SendMessage" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this UserSessionResource created on azure
// for more information of creating UserSessionResource, please refer to the document of UserSessionResource
string subscriptionId = "daefabc0-95b4-48b3-b645-8a753a63c4fa";
string resourceGroupName = "resourceGroup1";
string hostPoolName = "hostPool1";
string sessionHostName = "sessionHost1.microsoft.com";
string userSessionId = "1";
ResourceIdentifier userSessionResourceId = UserSessionResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, hostPoolName, sessionHostName, userSessionId);
UserSessionResource userSession = client.GetUserSessionResource(userSessionResourceId);
// invoke the operation
UserSessionMessage sendMessage = new UserSessionMessage
{
MessageTitle = "title",
MessageBody = "body",
};
await userSession.SendMessageAsync(sendMessage: sendMessage);
Console.WriteLine("Succeeded");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue