MS Graph API - Add Permissions DriveItem error Invite must be called with a list of recipientsrequest

Michael Smith (staff) 20 Reputation points
2023-05-19T20:35:09.73+00:00

I am trying to use Microsoft Graph API via python requests library to 1. create a sharelink to a folder in Onedrive and 2. change the permissions so that specific users who get the link can access it.

permission graph docs

Part 1 works. The response returned gives me the shareLink and encoded shareId. When I use the shareLink (and I obviously have permissions) it takes me to the folder.

Part 2 returns an error. The message attached to the error says:

'error': {'code': 'invalidRequest', 'message': 'Invite must be called with a list of recipients',

but...

I am supplying a list of recipients. As far as I can tell this seems to be same format as the example at bottom of above docs page!

request = json.dumps({
        "recipients": [{'email':'user@email.com'}],
        "roles": ["read"]
        })

response=requests.post(
        GRAPH_API_ENDPOINT + '/shares/' + share_id + '/permission/grant',
        headers=headers,
        json=request
        )
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,296 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
774 questions
0 comments No comments
{count} votes

Accepted answer
  1. Konstantinos Passadis 16,956 Reputation points
    2023-05-19T20:54:53.0933333+00:00

    Hello @Michael Smith (staff) !

    Welcome to Microsoft QnA!

    I understand that your request somehow it does not get recognized !

    Can you try this instead :

    request = {
            "recipients": [{'email':'user@email.com'}],
            "roles": ["read"]
            }
    
    response=requests.post(
            GRAPH_API_ENDPOINT + '/shares/' + share_id + '/permission/grant',
            headers=headers,
            json=request
            )
    
    
    
    

    The answer or portions of it may have been assisted by AI Source: ChatGPT Subscription

    Kindly mark the answer as Accepted and Upvote in case it helped or post your feedback to help !

    Regards

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful