msgraph-sdk-python icon indicating copy to clipboard operation
msgraph-sdk-python copied to clipboard

Account Enabled always returns None using Python SDK .get() — even with correct permissions

Open sumeet1495 opened this issue 5 months ago • 1 comments

Hi All,

I'm using the Microsoft Graph Python SDK and running the following code:

detailed_user = await client.users.by_user_id("user_id").get() print(detailed_user.account_enabled)

Even though my app has all the necessary application permissions (User.ReadWrite.All, Directory.ReadWrite.All, etc.) and admin consent is granted, the field account_enabled always returns None.

Is this a known limitation of the Python SDK?

sumeet1495 avatar Jul 23 '25 13:07 sumeet1495

Hi @sumeet1495 . The account_enabled field is not included in the response by default. To include it, you need to specify it in the select query parameters. Use UserItemRequestBuilder to add the query parameters, as shown in the template below. Simply add the user property names you want in your response within the select list. You can find all available properties for the user resource at https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0#properties.

# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.users.item.user_item_request_builder import UserItemRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
query_params = UserItemRequestBuilder.UserItemRequestBuilderGetQueryParameters(
		select = ["displayName","givenName","userPrincipalName","email", "accountEnabled"],
)

request_configuration = RequestConfiguration(
                 query_parameters = query_params,
)

result = await graph_client.users.by_user_id('user-id').get(request_configuration = request_configuration)

haaks98 avatar Oct 28 '25 18:10 haaks98