Hello Abhijith RP,
Thank you for reaching to Microsoft Support!To achieve this, you can use Microsoft Graph API’s extension attributes to store and retrieve custom properties like departmentCode
. Here’s a step-by-step guide to help you:
- Register an Application:
- Go to the Azure Portal.
- Navigate to Azure Active Directory > App registrations > New registration.
- Register your application.
- Grant API Permissions:
- In your registered application, go to API permissions.
- Add the following permissions:
- Directory.ReadWrite.All
- User.ReadWrite.All
- Grant admin consent for these permissions.
- Create and Assign Extension Attributes:
- Use the Microsoft Graph API to create an extension attribute. You can use the
schemaExtensions
endpoint to define a new schema extension. Please refer documentation. - Example request to create a schema extension:
- Use the Microsoft Graph API to create an extension attribute. You can use the
POST https://graph.microsoft.com/v1.0/schemaExtensions
Content-Type: application/json
{
"id": "Department",
"description": "Schema extension for department code",
"targetTypes": ["User"],
"properties": [
{
"name": "departmentCode",
"type": "String"
}
]
}
- Assign the extension attribute to a user:
PATCH https://graph.microsoft.com/v1.0/users/{user-id}
Content-Type: application/json
{
"yourSchemaExtensionName(id generated in step3)": "SomeCodeWhichUniquelyDefines"
}
Retrieve the Extension Attribute:
- To retrieve the Department Attribute for a user, use the following request:
GET https://graph.microsoft.com/v1.0/users/{user-id}?$select=yourSchemaExtensionName
This approach allows you to store a unique departmentCode that remains consistent even if the department name changes.
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.