Error when trying to update custom seccurity attribute assignments using graph sdk in C#: Invalid Property

Renezeder Markus 20 Reputation points
2023-03-22T10:25:19.16+00:00

After having problems with reading custom security attribute which I've solved by using Microsoft.Graph.Beta 5.22, I ran into the next problem.

If I try to update the value of a custom security attribute (like in https://learn.microsoft.com/en-us/graph/custom-security-attributes-examples?tabs=csharp) I get the following error message:

Request_BadRequest
Invalid property 'CsasAXCustomerData'.
Microsoft.Graph.Beta.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Graph.Beta.Models.ODataErrors.ODataError' was thrown.
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Graph.Beta.Users.Item.UserItemRequestBuilder.PatchAsync(User body, Action`1 requestConfiguration, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in C:\Projects\TestGraph\TestGraph\Program.cs:line 50

Here ist the code I use:

using Azure.Identity;
using Microsoft.Graph.Beta;
using Microsoft.Graph.Beta.Models;
using Microsoft.Graph.Beta.Models.ODataErrors;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Reflection;
using TestGraph;

var scopes = new[] { "https://graph.microsoft.com/.default" };

var tenantId = "<tenantid>";

var clientId = "<clientid>";
var clientSecret = "<clientSecret>;

var options = new TokenCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};

var clientSecretCredential = new ClientSecretCredential(
    tenantId, clientId, clientSecret, options);

var client = new GraphServiceClient(clientSecretCredential, scopes);

string userid = "<userid>";


try
{

    var requestBody = new User
    {
        CustomSecurityAttributes = new CustomSecurityAttributeValue
        {
            AdditionalData = new Dictionary<string, Object>
            {
                {
                    "CsasAXCustomerData", new
                    {
                        OdataType = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
                        CsaAXDataAreaId = "xxx",
                    }
                }
            }
        }
    };

    await client.Users[userid].PatchAsync(requestBody);

}
catch(ODataError odataError)
{
    Console.WriteLine(odataError.Error.Code);
    Console.WriteLine(odataError.Error.Message);

    Console.WriteLine(odataError.ToString());
}

CsasAXCustomerData is a Custom Security Attribute Set, CsaAXDataAreaId is a Custom Security Attribute with type of string.

The app registration has assigned the following API permissions:

  • CustomSecAttributeAssignment.ReadWrite.All (Application)
  • CustomSecAttributeDefinition.ReadWrite.All (Application)
  • Directory.Read.All (Delegated and Application)
  • Group.Read.All (Application)
  • GroupMember.Read.All (Application)
  • User.Read (Delegated)
  • User.Read.All (Application)
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,895 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,862 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,483 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Renezeder Markus 20 Reputation points
    2023-03-24T10:31:34.1566667+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.