This package can be used for generating a SharePoint token, and for uploading and downloading files from SharePoint.
Before you can use this package you have to create an "app registration" in SharePoint! In this section I will show you how!
- Create App Registration
This can be done by adding "_layouts/15/appregnew.aspx" to your SharePoint URL:
Example: https://yourorganisation.sharepoint.com/sites/MyTestSite/_layouts/15/appregnew.aspx
Fill in the app registration as follows:
Client-id: Press button
Client-secret: Press button
Title: You decide
App-domain: localhost
URI: https://localhost
For the upcoming steps you need to save "Client-id" and "Client-secret"
- Add permissions to App Registration
This can be done by adding "_layouts/15/appinv.aspx" to your SharePoint URL:
Example: https://yourorganisation.sharepoint.com/sites/MyTestSite/_layouts/15/appinv.aspx
Most of this part can be auto-generated by typing in you "Client-id" and then pressing the button. However, you still have to fill in the permissions XML your self.
Cheat Sheet for permissions:
https://medium.com/ng-sp/sharepoint-add-in-permission-xml-cheat-sheet-64b87d8d7600
XML for giving permissions to do everything:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />
</AppPermissionRequests>
-
List/delete existing app registrations:
You can see all app registations you have previously made, and delete them by adding "_layouts/15/AppPrincipals.aspx" to your SharePoint URL:
Example: https://yourorganisation.sharepoint.com/sites/MyTestSite/_layouts/15/AppPrincipals.aspx -
Get "tenent_ ID_id" and "resource_id":
The easiest way to get these two informations is to make a cURL call with verbose-mode enabled:
Example: curl -X GET -v -H "Authorization: Bearer" https://yourorganisation.sharepoint.com/sites/MyTestSite/_vti_bin/client.svc/
In the text you need to extract the following: Bearer realm="tenant ID" client_id="resource"
install.packages("devtools")
devtools::install_github("esbeneickhardt/sharepointr")
client_id <- "insert_from_first_step"
client_secret <- "insert_from_first_step"
tenant_id <- "insert_from_fourth_step"
resource_id <- "insert_from_fourth_step"
site_domain <- "yourorganisation.sharepoint.com"
sharepoint_url <- "https://yourorganisation.sharepoint.com/sites/MyTestSite"
sharepoint_token <- get_sharepoint_token(client_id, client_secret, tenant_id, resource_id, site_domain)
sharepoint_digest_value <- get_sharepoint_digest_value(sharepoint_token, sharepoint_url)
sharepoint_path <- "Shared Documents/test"
sharepoint_file_name <- "Mappe.xlsx"
out_path <- "C:/Users/User/Desktop/"
download_sharepoint_file(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path, sharepoint_file_name, out_path)
sharepoint_path <- "Shared Documents/test"
sharepoint_file_name <- "Mappe.xlsx"
out_path <- "C:/Users/User/Desktop/"
output_file <- "MyCustomFileName.xlsx"
download_sharepoint_file_with_custom_name(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path, sharepoint_file_name, out_path, output_file)
sharepoint_path <- "Shared Documents/test"
sharepoint_file_name <- "Test.xlsx"
file_path <- "C:/Users/User/Desktop/Test.xlsx"
upload_file_to_sharepoint(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path, sharepoint_file_name, file_path)
sharepoint_path <- "Shared Documents/test"
get_sharepoint_file_names(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path)
sharepoint_path <- "Shared Documents/test"
get_sharepoint_folder_names(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path)