Request_ResourceNotFound

Zhang Jiantang 0 Reputation points
2025-05-09T06:42:00.79+00:00

I was try to get the info of a service principle.

Error:

Resource 'xxx' does not exist or one of its queried reference-property objects are not present

Doc I followed: https://learn.microsoft.com/en-us/graph/api/serviceprincipal-get?view=graph-rest-1.0&tabs=python
The following is the code:

import pprint

from azure.identity import AzureAuthorityHosts

from azure.identity.aio import ClientSecretCredential

from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider

from msgraph import GraphServiceClient, GraphRequestAdapter

from msgraph.generated.models.password_profile import PasswordProfile

from msgraph.generated.models.user import User

from msgraph.generated.users.item.user_item_request_builder import UserItemRequestBuilder

from kiota_abstractions.base_request_configuration import RequestConfiguration

tenant_id = ""

client_id = ""

client_secret = ""

credential = ClientSecretCredential(

tenant_id=tenant_id,

client_id=client_id,

client_secret=client_secret,

authority=AzureAuthorityHosts.AZURE_CHINA

)

scopes = ['https://microsoftgraph.chinacloudapi.cn/.default']

auth_provider = AzureIdentityAuthenticationProvider(credential, scopes=scopes)

request_adapter = GraphRequestAdapter(auth_provider)

request_adapter.base_url = "https://microsoftgraph.chinacloudapi.cn/v1.0/"

graph_client = GraphServiceClient(request_adapter=request_adapter)

query_params = UserItemRequestBuilder.UserItemRequestBuilderGetQueryParameters(

	# select = ["displayName","givenName","postalCode","identities"],

)

request_configuration = RequestConfiguration(

query_parameters = query_params,

)

async def get_user():

#result = await graph_client.users.by_user_id('').owned_objects.get()

result = await graph_client.service_principals.by_service_principal_id('').get()

print(result)



#pprint.pprint(result)

import asyncio

asyncio.run(get_user())

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
24,511 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Zhang Jiantang 0 Reputation points
    2025-05-10T02:14:16.4566667+00:00

    I mistook APPLICATION for SERVICEPRINCIPLE. After modification, it worked:

    Original code:

    result = await graph_client.service_principals.by_service_principal_id('51e6baab-cff1-4dd3-a2ef-0xxxxxxxxxx').get()

    After modification:

    result = await graph_client.applications.by_application_id('51e6baab-cff1-4dd3-a2ef-0bxxxxxxxxxx').get()

    0 comments No comments

  2. Navya 18,215 Reputation points Microsoft External Staff Moderator
    2025-05-12T09:46:38.2533333+00:00

    Hi @Zhang Jiantang

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue:

    Attempting to retrieve information for a service principal using Python, but encountered the error:

    "Resource 'xxx' does not exist or one of its queried reference-property objects are not present."

    Solution:

    Issue resolved by @Zhang Jiantang

    After switching to the correct service principal, the script executed successfully.

    User's image

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    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.