Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
311 stars 43 forks source link

Add new `ms_drive_item` methods for item version history, analytics, retention labels, etc. #188

Open elipousson opened 11 months ago

elipousson commented 11 months ago

I'd be interested in seeing a feature added that allow the retrieval of the version history for a SharePoint item (especially a Word document) when returning the item metadata. This could also be handled as a separate method if that is more appropriate for the package design.

I know how to access the file version history from within Microsoft Word but I had difficulty finding any documentation on how this information can be handled programmatically. I do see that the .NET library has an option for working with document library versions: https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.tools.word.document.documentlibraryversions?view=vsto-2017#microsoft-office-tools-word-document-documentlibraryversions

I also found a couple of references to API endpoints here: https://community.fabric.microsoft.com/t5/Desktop/Getting-version-history-from-SharePoint-document-library/m-p/776338

And here: https://learn.microsoft.com/en-us/answers/questions/1076146/get-version-history-of-a-word-online-document-thro

This may be out of scope for the Microsoft365R package but, if so, I'd still welcome any tips on how to approach this within R. Thanks for the package!

hongooi73 commented 7 months ago

Going from that last link, this should get you the history:

obj <- sp$get_item("path/to/file")
obj$do_operation("versions")

Is that what you're after? Basically do_operation will let you run any Graph API method defined for that object.

elipousson commented 7 months ago

This is exactly what I wanted to do, @hongooi73. I didn't quite realize it was so simple to use the do_operation method! Would you be interested in seeing this feature added to the package? I could likely put together a pull request with this and a couple other open feature requests over the next couple weeks.

hongooi73 commented 7 months ago

That would be great! I recommend looking at the AzureGraph vignettes if you want to make a PR, there is a short intro on extending the object framework.

elipousson commented 7 months ago

Is this the vignette you are thinking of, @hongooi73?

It looks like there are a couple different API endpoints related to item changes, usage, retention, and versioning:

If it works for you, I may change the title of this issue to something a little broader and see if I can put together a pull request that adds a few new related method to the ms_item class objects all at once.

There isn't any kind of official test environment, right? I'd need to set something up with my own SharePoint access for myself to write and run tests?

hongooi73 commented 7 months ago

That would be great! There is a test environment, but it's just my own MS365 account right now. Any business account code is untested. So yeah, you'd have to mock something up on your own, unfortunately.

One note: List children is just your regular file listing, which is already implemented as list_files.

In terms of code style: have a look at the existing code and copy it. In particular, try not to use the Tidyverse unless absolutely necessary. One of my objectives is to avoid bloating the list of dependencies, and pulling in things like dplyr or tidyr can have a big impact. You also mentioned that you're not very familiar with R6. Do you know any of the big languages (Python, Java, C#, C++ etc)? R6 is basically how these other languages do object-oriented programming.

elipousson commented 7 months ago

Yeah, I mainly work in the tidyverse but I've done enough package development that I can handle alternate workflows in base R. I came to programming via urban planning and public health so R is the only language I "know" but I'm decent at adapting code samples and reading documentation even when it isn't something I'm familiar with.

I'll try to start with a small PR for a drive item version method to make sure I get the conventions right – should take a week or two at most. This package has been a big help to me since a colleague introduced it to me back in the fall so I'm excited to contribute back.