// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new AppRoleAssignment
{
PrincipalId = Guid.Parse("33ad69f9-da99-4bed-acd0-3f24235cb296"),
ResourceId = Guid.Parse("9028d19c-26a9-4809-8e3f-20ff73e2d75e"),
AppRoleId = Guid.Parse("ef7437e6-4f94-4a0a-a110-a439eb2aa8f7"),
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.ServicePrincipals["{servicePrincipal-id}"].AppRoleAssignedTo.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
"github.com/google/uuid"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewAppRoleAssignment()
principalId := uuid.MustParse("33ad69f9-da99-4bed-acd0-3f24235cb296")
requestBody.SetPrincipalId(&principalId)
resourceId := uuid.MustParse("9028d19c-26a9-4809-8e3f-20ff73e2d75e")
requestBody.SetResourceId(&resourceId)
appRoleId := uuid.MustParse("ef7437e6-4f94-4a0a-a110-a439eb2aa8f7")
requestBody.SetAppRoleId(&appRoleId)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
appRoleAssignedTo, err := graphClient.ServicePrincipals().ByServicePrincipalId("servicePrincipal-id").AppRoleAssignedTo().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
AppRoleAssignment appRoleAssignment = new AppRoleAssignment();
appRoleAssignment.setPrincipalId(UUID.fromString("33ad69f9-da99-4bed-acd0-3f24235cb296"));
appRoleAssignment.setResourceId(UUID.fromString("9028d19c-26a9-4809-8e3f-20ff73e2d75e"));
appRoleAssignment.setAppRoleId(UUID.fromString("ef7437e6-4f94-4a0a-a110-a439eb2aa8f7"));
AppRoleAssignment result = graphClient.servicePrincipals().byServicePrincipalId("{servicePrincipal-id}").appRoleAssignedTo().post(appRoleAssignment);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\AppRoleAssignment;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AppRoleAssignment();
$requestBody->setPrincipalId('33ad69f9-da99-4bed-acd0-3f24235cb296');
$requestBody->setResourceId('9028d19c-26a9-4809-8e3f-20ff73e2d75e');
$requestBody->setAppRoleId('ef7437e6-4f94-4a0a-a110-a439eb2aa8f7');
$result = $graphServiceClient->servicePrincipals()->byServicePrincipalId('servicePrincipal-id')->appRoleAssignedTo()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.app_role_assignment import AppRoleAssignment
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AppRoleAssignment(
principal_id = UUID("33ad69f9-da99-4bed-acd0-3f24235cb296"),
resource_id = UUID("9028d19c-26a9-4809-8e3f-20ff73e2d75e"),
app_role_id = UUID("ef7437e6-4f94-4a0a-a110-a439eb2aa8f7"),
)
result = await graph_client.service_principals.by_service_principal_id('servicePrincipal-id').app_role_assigned_to.post(request_body)