How do I enable anonymous access to a link created with microsoft graph api

Graham Jarvis 136 Reputation points
2021-08-12T16:41:05.467+00:00

Using the microsoft-graph library I am able to create shareable links as follows:

use Microsoft\Graph\Graph;  

$data = [  
                'type' => 'edit',  
                'scope' => 'organization',  
            ];  
            $url = '/drives/'.$driveId.'/items/'.$driveitemId.'/createLink';  
            $link = $this->graph->createRequest("POST", $url)  
                        ->attachBody($data)  
                        ->execute();  

The above is successful.

What I really want to do is create an 'anonymous' link so that people outside of the organization have access to the file. However, if I change the scope to 'anonymous' then the above link creation fails. Likewise, if I go to Onedrive on the web, I cannot share the link with anyone as it says that my organization is preventing me from selecting the option.

The API documentation does say that "Anonymous link support may be disabled by an administrator.", however it doesn't say where or how to enable or disable anonymous link support.

The idea is that the link will initially be editable, but will be later changed to read only.

Please could you tell me where I can enable this support so that I can manage the link using microsoft-graph API.

Apologies in advance @JosephXu-MSFT - you are the only person I know to tag, please forward as appropriate.

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

Accepted answer
  1. JosephXu-MSFT 531 Reputation points
    2021-08-13T02:31:46.913+00:00

    Hi @Graham Jarvis , I'm glad to do my best to help you. I found solution in this document. It says: we need to sign in with an account that has admin permissions for your organization.

    1. When we login with an admin account, click Admin center.
      122866-image.png
    2. Then click show all and we can see SharePoint, then click it.
      122925-image.png
    3. It will open a new page. Then we can click the following link.
      122855-image.png
    4. As the following picture shows. In the Policies -> Sharing menu bar, we can set to Anyone level. After that we can enable anonymous access. :)
      ![122896-image.png

    ## Update:

    Hi @Graham Jarvis Glad to hear that you got it works. We also can set site scope external sharing settings.

    1. Go to the Sharepoint Admin Centre
    2. Select "Active Sites'
    3. Select the site
    4. Click the 'Sharing' link found above the site list
    5. Under 'External Sharing' select 'Anyone'
    6. Save the change

    123050-image.png

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Graham Jarvis 136 Reputation points
    2021-08-13T09:26:55.283+00:00

    Thank you so much @JosephXu-MSFT

    Getting to the Sharepoint Admin area was the key! I checked the settings under Policies that you highlighted, but found that they were already set to 'Anyone with the link'. However, the page you highlighted above mentioned 'You can further restrict sharing for each individual site' and had a link to further explanation.

    To fully fix my problem I had to:

    1. Go to the Sharepoint Admin Centre (as shown in your answer)
    2. Select "Active Sites'
    3. Select the site (which corresponded to the relevant shared drive)
    4. Click the 'Sharing' link found above the site list
    5. Under 'External Sharing' select 'Anyone' (previously 'New and Existing Guests' had been selected)
    6. Save the change

    Following this change, my code snippet successfully created an Anonymous link.

    I'm happy to accept your answer, but I'm not sure whether you might want to add a note about also needing to check site settings too? Thank you again for pointing me in the right direction.

    1 person found this answer helpful.