Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client side paging using Microsoft OneDrive API/SDK

I am trying to implement client side paging using Microsoft OneDrive API/SDK. For that I need the total count of items as response from the API, and based on the skip and maximum limit value passed to the API, the response should be fetched.

In the List Items link, it is mentioned that we can achieve this using the query strings provided here. Based on this assumption, I am building the URL for API call as below:

string.Format("https://graph.microsoft.com/v1.0/me/drive/root/children?$skip={0}&$top={1}&$count=true",topValue*page, topValue)

Everything seems to be fine as per the info in the above mentioned URL, but I am getting "Bad Request" from the server with error message as shown below:

{
  "error": {
    "code": "",
    "message": "The query specified in the URI is not valid. Query option 'Skip' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.",
    "innerError": {
      "request-id": "384693d7-65bd-4dc6-8d60-afde68e01555",
      "date": "2017-04-25T10:28:15"
    }
  }
}


{
  "error": {
    "code": "",
    "message": "The query specified in the URI is not valid. Query option 'Count' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.",
    "innerError": {
      "request-id": "2188a06f-10cf-402c-9c49-bd296b9db614",
      "date": "2017-04-25T10:29:05"
    }
  }
}

Can this be achieved using REST APIs or Microsoft Graph SDK?

PS: I saw the concept of skipToken but that won't fit into our requirements as it does not return the total count and only incremental navigation is supported.

like image 702
Saket Kumar Avatar asked Apr 25 '17 10:04

Saket Kumar


1 Answers

It appears that a OneDrive engineer has already answered this question here:

OneDrive's paging model is a little different to skip+take. Essentially you'll make a query like:

GET https://graph.microsoft.com/v1.0/me/drive/root/children?$top=5

and in the response you should see the usual array of values, along with a property called @odata.nextLink. You'll want to take that URL use it request the next page:

"@odata.nextLink": "https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=ASDGASGSD"

GET https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=ASDGASGSD

You keep doing this until you don't get an @odata.nextLink returned.

like image 170
Reuben Tanner Avatar answered Oct 05 '22 22:10

Reuben Tanner