question

GrahamJarvis-8177 avatar image
1 Vote"
GrahamJarvis-8177 asked JosephXu-MSFT commented

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

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-sdkmicrosoft-graph-files
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JosephXu-MSFT avatar image
1 Vote"
JosephXu-MSFT answered JosephXu-MSFT edited

Hi @GrahamJarvis-8177, 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 @GrahamJarvis-8177 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



image.png (157.7 KiB)
image.png (19.0 KiB)
image.png (28.8 KiB)
image.png (41.8 KiB)
image.png (106.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GrahamJarvis-8177 avatar image
1 Vote"
GrahamJarvis-8177 answered JosephXu-MSFT commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @GrahamJarvis-8177 I've updated my answer. :)

0 Votes 0 ·