0

In a list I have some items. I want to call Rest api to list these items.

When I call the api url from the browser, I get the expected result (items are returned).

When I call the api from Insomnia Rest client, I get no result. By no result I mean the result set is returned without error, but empty.

What I've done :

  • in AAD portal, I registered a new application, a client ID and an App Secret.
  • I autorize (admin consent) :
    • Microsoft Graph : Sites.Read.All and Sites.ReadWrite.All
    • SharePoint : Sites.FullControl.All, Sites.Manage.All, Sites.Read.All and Sites.ReadWrite.All
  • in insomnia, I set up OAuth 2.0 authentication :
    • Grant type : Authorization Code
    • Authorization Url : https://login.microsoftonline.com/common/oauth2/authorize?resource=https://mytenant.sharepoint.com
    • Access token Url: https://login.microsoftonline.com/common/oauth2/token
    • Client ID: my generated client ID
    • Client secret : my generated secret
    • Redirect URL : https://login.microsoftonline.com/common/oauth2/nativeclient
    • Header : only Accept=application/json;odata=verbose because authentication headers are handled by insomnia.

The url I target is https://mytenant.sharepoint.com/sites/mysitecoll/_api/Web/Lists(guid'b6e9527d-a902-4b15-b77b-d49e701fdd92')/items.

The result of this call is (status 200 OK):

{
  "d": {
    "results": []
  }
}

As you can see there's no error, but no data.

What's puzzling me is that calling : https://mytenant.sharepoint.com/sites/mysitecoll/_api/Web/Lists(guid%27b6e9527d-a902-4b15-b77b-d49e701fdd92%27)?%24select=ItemCount actually returns :

{
  "d": {
    "__metadata": {
      ....
    },
    "ItemCount": 3
  }
}

There is data.

What's missing ?

As a side note, using the Graph, everything is ok : https://graph.microsoft.com/v1.0/sites/mytenant.sharepoint.com,b969074a-6a95-4235-a520-17893eca8fbe,4d32dad1-6bcc-4b57-becc-7e476c851046/lists/b6e9527d-a902-4b15-b77b-d49e701fdd92/items returns expected data

2 Answers 2

0

It's a problem with permissions..

For test just try to add permissions to specific list/library

<AppPermissionRequests AllowAppOnlyPolicy="true">  
  <AppPermissionRequest
    Scope="http://sharepoint/content/sitecollection/web/list" 
    Right="FullControl"
  />
</AppPermissionRequests>

And choose list/library in a step after you press create..

1
  • Thanks for you help, but this ACS permission, not AAD permission
    – Steve B
    Commented Nov 18, 2022 at 7:12
0

I had the same issue. Later I found I made a mistake on the below Scope attribute value. I was putting my List URL below but it is actually a static text

Scope="http://sharepoint/content/sitecollection/web/list" 
1
  • Thanks for you help, but this ACS permission, not AAD permission
    – Steve B
    Commented Nov 18, 2022 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.