Graph Api issue trying to update contact to outlook global address list in an organisation

Pavan Goud 20 Reputation points
 def __init__(self, tenant_id, client_id, client_secret):
        self.tenant_id = tenant_id
        self.client_id = client_id
        self.client_secret = client_secret
        self.contacts_endpoint_base = ''
        self.credential = ClientSecretCredential(
        self.token_response = self.credential.get_token("")
        self.headers = {
            'Authorization': f'Bearer {self.token_response.token}',
            'Content-Type': 'application/json'
        self.initialize_csv()"ContactManager initialized successfully")

Note: I tried to use endpoint /contacts and also /users to update no luck User's image


2024-06-04 15:00:38,164 - INFO - ClientSecretCredential.get_token succeeded

2024-06-04 15:00:38,167 - INFO - ContactManager initialized successfully

2024-06-04 15:00:38,176 - DEBUG - Starting new HTTPS connection (1):

2024-06-04 15:00:38,865 - DEBUG - "GET /v1.0/me/contacts?$ HTTP/1.1" 400 None

2024-06-04 15:00:38,865 - ERROR - Failed to retrieve contacts: 400 Client Error: Bad Request for url:$

2024-06-04 15:00:38,869 - ERROR - Failed to search contacts: 400 Client Error: Bad Request for url:$

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,101 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yakun Huang-MSFT 1,400 Reputation points Microsoft Vendor

    Hi @Pavan Goud

    The access /me/contacts endpoint does not support the use of the client credential flow, which requires user participation to access, and the client credential flow does not have user participation, so please use auth code flow to access on behalf of the user, and use the delegation permissions Contacts.Read or Contacts.ReadWrite.

    Refer to the code below.

    scopes = ['User.Read']
    # Multi-tenant apps can use "common",
    # single-tenant apps must use the tenant ID from the Azure portal
    tenant_id = 'common'
    # Values from app registration
    client_id = 'YOUR_CLIENT_ID'
    client_secret = 'YOUR_CLIENT_SECRET'
    redirect_uri = 'YOUR_REDIRECT_URI'
    # For authorization code flow, the user signs into the Microsoft
    # identity platform, and the browser is redirected back to your app
    # with an authorization code in the query parameters
    authorization_code = 'AUTH_CODE_FROM_REDIRECT'
    # azure.identity.aio
    credential = AuthorizationCodeCredential(
    graph_client = GraphServiceClient(credential, scopes) # type: ignore

    More details can be found at this link:

    Hope this helps.

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

    0 comments No comments