Skip to content

Latest commit

 

History

History
258 lines (197 loc) · 8.74 KB

File metadata and controls

258 lines (197 loc) · 8.74 KB
author learafa
title Grant permission
description Grant a list of users access to use the specified link
ms.localizationpriority medium
ms.subservice sharepoint
doc_type apiPageType
ms.date 04/04/2024

permission: grant

Namespace: microsoft.graph

Grant users access to a link represented by a permission.

[!INCLUDE national-cloud-support]

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

[!INCLUDE permissions-table]

HTTP request

POST /shares/{encoded-sharing-url}/permission/grant

Path parameters

Parameter Name Value Description
encoded-sharing-url string Required. A properly encoded sharing URL.

Encoding sharing URLs

To encode a sharing URL, use the following logic:

  1. First, use base64 encode the URL.
  2. Convert the base64 encoded result to unpadded base64url format by removing = characters from the end of the value, replacing / with _ and + with -.)
  3. Append u! to be beginning of the string.

As an example, to encode a URL in C#:

string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');

Request headers

Name Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.

Request body

In the request body, provide a JSON object with the following parameters.

{
  "recipients": [
    { "@odata.type": "microsoft.graph.driveRecipient" }
  ],
  "roles": [ "read | write"]
}
Parameter Type Description
recipients driveRecipient collection A collection of recipients who receive access.
roles String collection If the link is an "existing access" link, specifies roles to be granted to the users. Otherwise must match the role of the link.

For a list of available roles, see roles property values.

Response

If successful, this method returns a 200 OK response code and a permission collection in the response body.

A permission representing the updated link will always be returned in the result set on success. The updated link can be identified by the presence of a 'link' facet containing the 'scope' property. In some cases it may be possible that the updated link has a different URL than the original link, in which case the new URL should be used.

Read the Error Responses topic for more info about how errors are returned.

Example

This example grants the users john@contoso.com and ryan@external.com access to a sharing link without modifying other existing permissions on the link.

Request

POST https://graph.microsoft.com/v1.0/shares/{encoded-sharing-url}/permission/grant
Content-type: application/json

{
  "recipients": [
    {
      "email": "john@contoso.com"
    },
    {
      "email": "ryan@external.com"
    }
  ],
  "roles": ["read"]
}

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

HTTP/1.1 200 OK
Content-type: application/json

{
  "value": [
    {
      "hasPassword": false,
      "id": "5fab944a-47ec-48d0-a9b5-5178a926d00f",
      "link": {
        "preventsDownload": false,
        "scope": "users",
        "type": "view",
        "webUrl": "https://contoso.sharepoint.com/:t:/g/design/EZexPoDjW4dMtKFUfAl6BK4BvIUuss52hLYzihBfx-PD6Q"
      },
      "roles": [
        "read"
      ]
    }
  ]
}

Note: The response object shown here might be shortened for readability.

If the link is an existing access link, additional permissions will be returned representing the following:

  • User-type permissions representing recipients who were successfully granted access. These can be identified by presence of the grantedTo property.
  • Link-type permissions representing invitations that need to be sent to unrecognized external users for them to gain access. These can be identified by the presence of an invitation facet. These entries will contain a link with the invitation URL, and the grantedToIdentities collection will indicate the users to whom the link should be sent.
HTTP/1.1 200 OK
Content-type: application/json

{
  "value": [
    {
      "hasPassword": false,
      "id": "00000000-0000-0000-0000-000000000000",
      "link": {
        "preventsDownload": false,
        "scope": "existingAccess",
        "type": "view",
        "webUrl": "https://contoso.sharepoint.com/teams/design/shareddocs/Document.docx"
      },
      "roles": [
        "read"
      ]
    },
    {
      "grantedTo": {
        "user": {
          "displayName": "John Smith",
          "email": "john@contoso.com",
          "id": "47aecee2-d061-4730-8ecb-4c61360441ae"
        }
      },
      "id": "aTowIy5mfG1lbWJlcnNoaXB8bGltaXRlZDJAa2xhbW9kYi5vbm1pY3Jvc29mdC5jb20",
      "roles": [
        "read"
      ]
    },
    {
      "grantedToIdentities": [
        {
          "user": {
            "email": "ryan@external.com"
          }
        }
      ],
      "invitation": {
        "signInRequired": true
      },
      "roles": [
        "read"
      ],
      "link": {
        "type": "view",
        "webUrl": "https://contoso.sharepoint.com/:t:/g/teams/design/EZexPoDjW4dMtKFUfAl6BK4Bw_F7gFH63O310A7lDtK0mQ"
      }
    }
  ]
}

Note: The response object shown here might be shortened for readability.