Johannes
Johannes

Reputation: 23

Microsoft Graph SDK and SharePoint List items

i'm trying to retrieve all items from a Tasklist in a SharePoint Projectsite with this function:

    public async Task<string> GetTasks(GraphServiceClient graphClient, string siteId, string listId)
    {
        string requestUrl = "https://graph.microsoft.com/v1.0/sites/" + siteId + "/lists/" + listId + "/items?expand=fields";

        HttpRequestMessage hrm = new HttpRequestMessage(HttpMethod.Get, requestUrl);

        await graphClient.AuthenticationProvider.AuthenticateRequestAsync(hrm);

        HttpResponseMessage response = await graphClient.HttpProvider.SendAsync(hrm);

        if (response.IsSuccessStatusCode)
        {
            string content = await response.Content.ReadAsStringAsync();
            return content;
        }
        else
            throw new ServiceException(
                new Error
                {
                    Code = response.StatusCode.ToString(),
                    Message = await response.Content.ReadAsStringAsync()
                });
    }

but the response content is empty:

@odata.context":"https://graph.microsoft.com/v1.0/$metadata#sites('xxxxxxxxxx.com%2Cde7be133-babf-4bc9-8e52-857657f8fdd6%2C379cb706-d430-4dfc-8347-f2c8bc92a38c')/lists('eca2429f-44b7-4d68-af81-f5e56fece3ab')/items","value":[]}

I don't understand why the response is empty. In the Graph Explorer it is returning the data. Can someone explain this?

Thanks

Upvotes: 2

Views: 1248

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59318

Since you query SharePoint List Items, Sites.Read.All or Sites.ReadWrite.All permission scope needs to be specified.

According to documentation:

Sites.Read.All Read items in all site collections

Permission scopes per list type:

  • SharePoint List: Sites.Read.All,Sites.ReadWrite.All
  • SharePoint Library: Files.Read.All,Files.ReadWrite.All

Upvotes: 2

Related Questions