Microsoft Graph API : Status Code: Forbidden, Insufficient privileges to complete the operation.

Holysmokes-6260 41 Reputation points
2021-01-01T11:47:00.85+00:00

Hi there,

Not sure how to resolve this error on Title

I am getting this error, when I call this instruction and it's seems that I have given the application permissions

    var results = await _graphServiceClient.Contacts  
        .Request()  
        .GetAsync();  

This is the snap shot of application permission imposed on azure portal

52708-screenshot-1.png

And in the token I presenting before call the graph api is
52677-screenshot-2.png

If I change the code to users, it seems to be running with no problems

    var results = await _graphServiceClient.Users  
        .Request()  
        //.Select(f => f.Contacts)  
        .GetAsync();  

Not sure how to resolve this error and remember I use the free version of Azure.

Thanks,
Holy

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

3 answers

Sort by: Most helpful
  1. Holysmokes-6260 41 Reputation points
    2021-01-04T09:35:35.76+00:00

    Thanks. I hope this is enough.

    {
    "error": {
    "code": "Authorization_RequestDenied",
    "message": "Insufficient privileges to complete the operation.",
    "innerError": {
    "date": "2021-01-04T09:32:12",
    "request-id": "a666e0c6-dd9a-4526-8266-f5b9a804bb8a",
    "client-request-id": "a666e0c6-dd9a-4526-8266-f5b9a804bb8a"
    }
    }
    }

    0 comments No comments

  2. Shiva Keshav Varma 411 Reputation points
    2021-01-04T10:24:18.023+00:00

    You need to specify for whom you need to get the contacts. Since you are using App token which has application permissions you need to write the code as shown below.

    var contacts = await graphClient.Users["Shiva@nishantsingh.live"].Contacts
                                .Request()
                                .GetAsync();
    

    If you use User token then you need to write the code as shown below.

    var contacts = await graphClient.Me.Contacts
                                .Request()
                                .GetAsync();
    

    (If the reply was helpful please don't forget to upvote or accept as answer, thank you)

    0 comments No comments

  3. Holysmokes-6260 41 Reputation points
    2021-01-04T10:55:49.587+00:00

    Hi there,

    Now I get this error after changing this code to Me.Contacts. Remember I don't have azure license and I trying here with the basic free version.

    Code: ErrorAccessDenied
    Message: Access is denied. Check credentials and try again.
    ClientRequestId: 174ec2fc-5f90-4d41-91f3-5270b57c56ca

    Thanks


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.