JoshG
JoshG

Reputation: 6735

Editing custom Azure B2C attributes using Microsoft Graph Explorer

I am trying to use the Microsoft Graph Explorer to update a custom attribute I created in B2C named GroupID.

First, I get the id of the user I want to edit using this query:

GET https://graph.microsoft.com/v1.0/{myResourceName}.onmicrosoft.com/users

This returns the following JSON:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
    "value": [
        {
            "displayName": "User Name",
            "surname": "Name",
            "givenName": "User",
            "id": "ff46335221e1a365",
            "userPrincipalName": "[email protected]",
            "businessPhones": [],
            "jobTitle": null,
            "mail": null,
            "mobilePhone": null,
            "officeLocation": null,
            "preferredLanguage": null
        }
    ]
}

Now I'd like to add a value for GroupID for this user. The attribute itself does not appear in the above JSON, presumably because it does not yet have a value assigned.

I tried using this query:

PATCH https://graph.microsoft.com/v1.0/{myResourceName}.onmicrosoft.com/users/ff46335221e1a365

With request body:

{"GroupID": 1234}

But I get a 405 error:

The method or operation is not allowed.

Am I using the wrong query? I tried to follow the guide here.

UPDATE

Attached is a screenshot of the request. In this screenshot, I omitted the {myResourceName}.onmicrosoft.com from the URL. But I've tried both ways and still get the 405 error.

screenshot

Upvotes: 1

Views: 705

Answers (1)

Allen Wu
Allen Wu

Reputation: 16438

Please see this document:

Extension attributes in the Graph API are named by using the convention extension_ApplicationClientID_attributename, where the ApplicationClientID is the Application (client) ID of the b2c-extensions-app application (found in App registrations > All Applications in the Azure portal). Note that the Application (client) ID as it's represented in the extension attribute name includes no hyphens. For example:

"extension_831374b3bd5041bfaa54263ec9e050fc_loyaltyNumber": "212342"

So the real custom attribute name is extension_{ApplicationClientID}_GroupID.

Go to Azure AD -> App registrations to find the application id of the b2c-extensions-app application.

The {ApplicationClientID} is the application id without hyphens.

PATCH https://graph.microsoft.com/v1.0/users/ff46335221e1a365

{"extension_{ApplicationClientID}_GroupID": 1234}

Upvotes: 2

Related Questions