Can I get a list of all Shared Mailboxes/folders using Microsoft Graph Api

Bhanu 25 Reputation points
2023-02-06T12:31:08.1966667+00:00

I am trying to fetch the list of all shared mailbox folder list using graph API but i didn't found any API doc in Microsoft graph api document link. I have founded the API when it will return me the inbox messages list of that particular shared mailbox. Its not enough to me according to my requirement because i didnt know about the folder or user who will shared the mailbox with me so i need all the process will work using the graph api.

Thanks

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

4 answers

Sort by: Most helpful
  1. Michel Drenth 10 Reputation points
    2023-12-18T15:09:00.8033333+00:00
    def _getMailboxes():
        
        users = make_graph_call('https://graph.microsoft.com/v1.0/users', pagination=True)
    
    
        token_result = client.acquire_token_silent(scope, account=None)
        if token_result:
                access_token = 'Bearer ' + token_result['access_token']
                print('Access token was loaded from cache')
        else:
            token_result = client.acquire_token_for_client(scopes=scope)
            access_token = 'Bearer ' + token_result['access_token']
            print('New access token was acquired from Azure AD')
    
        if 'access_token' in token_result:
            headers = {
                'Authorization': access_token
            }
    
    
        for user in users:
            user_id     = user['id']
            displayName = user['displayName']
            jobTitle    = user['jobTitle']
            mail        = user['mail']
    
            url = f'https://graph.microsoft.com/v1.0/users/{user_id}/mailboxSettings'
    
            try:
                graph_result = requests.get(url=url, headers=headers).json()
                #print(graph_result)
                
                if 'userPurpose' in graph_result:
                    userPurpose    = graph_result.get('userPurpose')
                    if userPurpose == 'shared':
                        print(f"shared mailbox {displayName}: {mail}")
    
    
            except Exception as e:
                print(f"Fout bij het ophalen van gegevens: {e}")
                    
    
    1 person found this answer helpful.
    0 comments No comments

  2. Gerben Tiele 11 Reputation points
    2024-04-19T11:46:45.64+00:00

    It's possible now with Get-MgUserMailboxSetting

    Get-MgUser | Select-Object UserPrincipalName, @{Name='MailboxType';Expression={(Get-MgUserMailboxSetting -UserId $_.UserPrincipalName).UserPurpose}} | Where-Object {$_.MailboxType -Eq 'shared'}
    
    1 person found this answer helpful.

  3. CharanyaB-MSFT 1,891 Reputation points Microsoft Vendor
    2023-02-06T18:11:17.44+00:00

    Hi @Bhanu,

    You can get the particular shared folder using graph API by providing the shared mailbox email address or user id.

    Currently, there is no Microsoft Graph API or Microsoft Graph PowerShell SDK available to list all the shared mailboxes.
    You can upvote this features request idea Get a list of shared mailboxes, including permissions and based on number of votes received Microsoft Engineering will consider for implementation.

    However, you can use Exchange Online PowerShell script to achieve this requirement and please find the relevant PowerShell command from documentation links below:

    https://learn.microsoft.com/en-us/exchange/recipients-in-exchange-online/manage-user-mailboxes/use-powershell-to-display-mailbox-information
    https://techcommunity.microsoft.com/t5/office-365/listing-shared-mailboxes-and-members-powershell/m-p/241737

    Hope this helps.

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


  4. JeGO_BE 21 Reputation points
    2023-03-09T12:00:43.4433333+00:00

    Maybe you can get a solution by making a MS Graph request to "list users" and by adding some filters to certain synced Exchange AD attributes?

    https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http

    https://learn.microsoft.com/en-us/azure/active-directory/hybrid/reference-connect-sync-attributes-synchronized

    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.