Search code examples
microsoft-graph-apionedrive

Is 'Word as a Service' possible via MS Graph API?


I have found some, but not all, pieces of the puzzle.

Using Graph APIs, when a user selects a document in my own web application, I can:-

  1. Create a new temporary folder in their OneDrive account
  2. Upload my.docx file to this location
  3. Get the url for my.docx
  4. Open the URL in a new tab, loading Office 365's MSWord editor (or viewer and editor after one more click)

This is where it gets a bit trickier. How can I get the edited content back into the location where my web application historically stored these documents?

Theorising, I can:-

  1. Create a webhook subscription to the new folder I create
  2. Implement a webhook listener (and validation) service

When the listener receives an 'update' notice for the document:-

  1. Call the download(content) API, or from the driveItem metadata, download it from @microsoft.graph.downloadUrl
  2. Persist it to my desired location within my web application

To me this sounds like it'll suffer from big delays. The webhook subscriptions typically send batches of changes and the frequency looks uncertain. It certainly wouldn't be great for versioning every individual save operation during the editing session.

Have I missed some more obvious path to Word as a Service? i.e. another API or a mixture of APIs?

Alternatives I've considered but haven't yet scoped: implement WOPI or WebDav within my own web application.


Solution

  • It sounds like you're only using OneDrive to take advantage of its built-in support for the MS-WOPI protocol. WOPI is basically an enhanced WebDav interface that is used by Office to work with remote document (i.e. files stored on OneDrive, Box, DropBox, etc.).

    Your solution is generally fine and it is certainly easy enough to orchestrate. You can absolutely use webhooks to subscribe to changes to the file. You'll likely want some mechanism in your app to notify your system when they're "done" so you can clean up the file afterwards.

    If you want a more robust solution, you'll need to look at WOPI. Implementing WOPI would allow you to keep these files on your system permanently. Office Online would use the WOPI interface to speak with your storage system and open/save/edit files in-place.

    Keep in mind that implementing WOPI (or any protocol for that matter) is often a non-trivial endeavor. You will also need to get your final solution validated and whitelisted by Office before it can be used. Details on this process and how to request access can be found at the Microsoft Cloud Storage Provider Program website.