// 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("9028d19c-26a9-4809-8e3f-20ff73e2d75e"),
ResourceId = Guid.Parse("8fce32da-1246-437b-99cd-76d1d4677bd5"),
AppRoleId = Guid.Parse("498476ce-e0fe-48b0-b801-37ba7e2685c6"),
};
// To initialize your graphClient, see https://zcusa.951200.xyz/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.ServicePrincipals["{servicePrincipal-id}"].AppRoleAssignments.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("9028d19c-26a9-4809-8e3f-20ff73e2d75e")
requestBody.SetPrincipalId(&principalId)
resourceId := uuid.MustParse("8fce32da-1246-437b-99cd-76d1d4677bd5")
requestBody.SetResourceId(&resourceId)
appRoleId := uuid.MustParse("498476ce-e0fe-48b0-b801-37ba7e2685c6")
requestBody.SetAppRoleId(&appRoleId)
// To initialize your graphClient, see https://zcusa.951200.xyz/en-us/graph/sdks/create-client?from=snippets&tabs=go
appRoleAssignments, err := graphClient.ServicePrincipals().ByServicePrincipalId("servicePrincipal-id").AppRoleAssignments().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("9028d19c-26a9-4809-8e3f-20ff73e2d75e"));
appRoleAssignment.setResourceId(UUID.fromString("8fce32da-1246-437b-99cd-76d1d4677bd5"));
appRoleAssignment.setAppRoleId(UUID.fromString("498476ce-e0fe-48b0-b801-37ba7e2685c6"));
AppRoleAssignment result = graphClient.servicePrincipals().byServicePrincipalId("{servicePrincipal-id}").appRoleAssignments().post(appRoleAssignment);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\AppRoleAssignment;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AppRoleAssignment();
$requestBody->setPrincipalId('9028d19c-26a9-4809-8e3f-20ff73e2d75e');
$requestBody->setResourceId('8fce32da-1246-437b-99cd-76d1d4677bd5');
$requestBody->setAppRoleId('498476ce-e0fe-48b0-b801-37ba7e2685c6');
$result = $graphServiceClient->servicePrincipals()->byServicePrincipalId('servicePrincipal-id')->appRoleAssignments()->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://zcusa.951200.xyz/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AppRoleAssignment(
principal_id = UUID("9028d19c-26a9-4809-8e3f-20ff73e2d75e"),
resource_id = UUID("8fce32da-1246-437b-99cd-76d1d4677bd5"),
app_role_id = UUID("498476ce-e0fe-48b0-b801-37ba7e2685c6"),
)
result = await graph_client.service_principals.by_service_principal_id('servicePrincipal-id').app_role_assignments.post(request_body)