Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error from Users sample code SEARCH USER BY NAME #671

Closed
pauljstuart opened this issue Apr 17, 2024 · 3 comments · Fixed by microsoft/kiota#4578
Closed

Error from Users sample code SEARCH USER BY NAME #671

pauljstuart opened this issue Apr 17, 2024 · 3 comments · Fixed by microsoft/kiota#4578
Labels
priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs type:breaking-change An issue that will result in dependent client projects failing.

Comments

@pauljstuart
Copy link

This sample code is from user_samples.md

When I run it, I get this error :

**request_configuration =  UsersRequestBuilder.UsersRequestBuilderGetRequestConfiguration(  query_parameters=query_params, )
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

AttributeError: type object 'UsersRequestBuilder' has no attribute 'UsersRequestBuilderGetRequestConfiguration'**

I am using python 3.12 and msgraph-sdk version 1.3.0.

Any idea what is causing this?

Is it the version of the msgraph-sdk old? This came from pypi.

import asyncio

from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
from msgraph.generated.users.users_request_builder import UsersRequestBuilder


async def find_user(user_name: str, client: GraphServiceClient) -> None:
    # The query used here is the same when searching for users in Azure AD via web console
    query_params = UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(
        search=[
            f'("displayName:{user_name}" OR "mail:{user_name}" OR "userPrincipalName:{user_name}" OR "givenName:{user_name}" OR "surName:{user_name}" OR "otherMails:{user_name}")'
        ],
    )
    request_configuration = (  UsersRequestBuilder.UsersRequestBuilderGetRequestConfiguration(  query_parameters=query_params, ) 
   )
    
    request_configuration.headers.add("ConsistencyLevel", "eventual")

    response = await client.users.get(request_configuration=request_configuration)
    if response.value:
        user = response.value[0]
        print(
            f"Found user for {user_name} in the Azure AD with user principal name {user.user_principal_name} and display name {user.display_name}"
        )
    else:
        print(f"{user_name} user in the Azure AD not found")


def main():
    # Use cli credentials to authenticate against Azure
    # Before running script do `az login`
    #credential = AzureCliCredential()

    SP_CLIENT_ID='yyyy'
    SP_TENANT_ID='zzzzz'
    SP_SECRET='xxx'  

    scopes = ['https://graph.microsoft.com/.default']
    credential = ClientSecretCredential(SP_TENANT_ID,
                                   SP_CLIENT_ID,
                                    SP_SECRET)

    client = GraphServiceClient(credentials=credential, scopes=scopes)
    asyncio.run(find_user("stuartp", client))


main()
@krisdevopsbot
Copy link

krisdevopsbot commented Apr 18, 2024

All of the samples are outdated and were broken by #668 , pip install 1.2.0 and it'll work or review the API changes and make the updates accordingly

@pauljstuart
Copy link
Author

Great thanks!

@shemogumbe shemogumbe added type:breaking-change An issue that will result in dependent client projects failing. priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs labels Apr 22, 2024
@shemogumbe
Copy link
Collaborator

shemogumbe commented Apr 22, 2024

Thanks for raising this,
We we investigate and find a solution, you can try to:

  1. Downgrade to V1.2.0 of the SDK.
  2. Try out this workaround:
+from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph import GraphServiceClient
from msgraph.generated.groups.groups_request_builder import GroupsRequestBuilder
graph_client = GraphServiceClient(credentials, scopes)
query_params = GroupsRequestBuilder.GroupsRequestBuilderGetQueryParameters(
		filter = "startswith(displayName, 'a')",
		count = True,
		top = 1,
		orderby = ["displayName"],
)
-request_configuration = GroupsRequestBuilder.GroupsRequestBuilderGetRequestConfiguration(
+request_configuration = RequestConfiguration(
query_parameters = query_params,
)
request_configuration.headers.add("ConsistencyLevel", "eventual")
result = await graph_client.groups.get(request_configuration = request_configuration)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p0 Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs type:breaking-change An issue that will result in dependent client projects failing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants