Microsoft Graph Files API - not downloading the latest version of the file

gowtham mithra 5 Reputation points
2023-03-16T07:36:13.56+00:00

I am using graph api to download file from Sharepoint online but I am not getting the latest version.

Below is my scenario :-

  1. Open excel file in Sharepoint online with persistence session using graph api.
  2. Populate it with data using graph api
  3. At this point Sharepoint online automatically creates a version of the file.
  4. Download file through graph api (GET /drives/{drive-id}/items/{item-id}/content). The downloaded file doesn't have the latest data.
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,618 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Shivam Dhiman 5,946 Reputation points
    2023-03-17T08:23:02.63+00:00

    Hi @gowtham mithra

    As per the documentation, If you have more than one call to make within a certain period of time, we recommend that you create a session and pass the session ID with each request. To represent the session in the API, use the workbook-session-id: {session-id} header. By doing so, you can use the Excel APIs in the most efficient way.
    As a best practice, Please follow the below steps:

    1. Create a session.
       POST https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/createSession
       Content-type: application/json
       
       {
         "persistChanges": true
       }
    
      2.  Perform all the action (Populate it with data) 
    
      3.  Close the session after all the requests are completed.
    
       POST https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/closeSession
       Content-type: application/json
       workbook-session-id:
       {session-id}
       {}
    
    
      4.  Now, the downloaded file will have the latest data. 
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.