Need help with Microsoft Graph Client

Mylapravan, Amith 0 Reputation points

i am trying to access email from outlook with the subject line Verififcation Email , below is the error and my code please assist on the same

from azure.identity.aio import ClientSecretCredential
from msgraph import GraphServiceClient
import warnings
import asyncio

from msgraph.generated.admin.service_announcement.messages.messages_request_builder import MessagesRequestBuilder

# Filter out the NotOpenSSLWarning
warnings.simplefilter("ignore", category=UserWarning)

async def main():
    credential = ClientSecretCredential(

    scopes = ['User.Read', 'Mail.ReadWrite', 'Mail.Read']
    client = GraphServiceClient(credential, scopes=scopes)

    user_id_or_upn = ""  # Replace with the user's ID or UPN
    messages_request = client.users.by_user_id(user_id_or_upn).mail_folders.by_mail_folder_id('inbox').messages

    query_params = MessagesRequestBuilder.MessagesRequestBuilderGetQueryParameters(
        filter="subject eq 'Verification Email'"
    request_config = MessagesRequestBuilder.MessagesRequestBuilderGetRequestConfiguration(
    messages = await messages_request.get(request_config)

loop = asyncio.get_event_loop()

Content: {"error":"invalid_scope","error_description":"AADSTS1002012: The provided value for scope User.Read is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).\r\nTrace ID: 2f3cdbf3-1c31-46c8-b2c7-555164872f00\r\nCorrelation ID: 9b0dd751-9049-475a-b496-8a7d366bd301\r\nTimestamp: 2023-08-26 13:52:47Z","error_codes":[1002012],"timestamp":"2023-08-26 13:52:47Z","trace_id":"2f3cdbf3-1c31-46c8-b2c7-555164872f00","correlation_id":"9b0dd751-9049-475a-b496-8a7d366bd301"}

A family of Microsoft email and calendar products.
1,808 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
2,081 questions
Microsoft Graph SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
991 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SokiGuo-MSFT 16,126 Reputation points Microsoft Vendor

    Hi @Mylapravan, Amith

    Welcome to our forum!

    Please kindly understand that the Outlook tag here we mainly focus on general issues about Outlook desktop client. Looks like the issue is more related to Graph API, which we are not very familiar. The following is for informational purposes only.

    Based on my search, the reasons for the error code AADSTS1002012 could be:

    The provided value for scope {scope} is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).

    User's image

    Also, I found a similar thread, you can refer to:

    Hope this helps!

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments