Giter Club home page Giter Club logo

sharepointr's Introduction

Introduction

This package can be used for generating a SharePoint token, and for uploading and downloading files from SharePoint.

Before using this Package

Before you can use this package you have to create an "app registration" in SharePoint! In this section I will show you how!

  1. 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"

  1. 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>
  1. 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

  2. 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"

Using the package

Installation

install.packages("devtools")
devtools::install_github("esbeneickhardt/sharepointr")

Parameters

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"

Getting a 1 hour SharePoint token

sharepoint_token <- get_sharepoint_token(client_id, client_secret, tenant_id, resource_id, site_domain)

Getting sharepoint digest value

sharepoint_digest_value <- get_sharepoint_digest_value(sharepoint_token, sharepoint_url)

Downloading a file from sharepoint

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)

Downloading a file from sharepoint with custom filename

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)

Uploading a file to sharepoint

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)

Listing files in a sharepoint

sharepoint_path <- "Shared Documents/test"
get_sharepoint_file_names(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path)

Listing folders in a sharepoint

sharepoint_path <- "Shared Documents/test"
get_sharepoint_folder_names(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path)

sharepointr's People

Contributors

esbeneickhardt avatar

Stargazers

 avatar  avatar Olivier B. avatar  avatar  avatar John Carty avatar Enrico Spinielli avatar Neal avatar Søren Havelund Welling avatar

Watchers

 avatar

sharepointr's Issues

Unable to get sharepoint digest value

Running
> sharepoint_digest_value <- get_sharepoint_digest_value(sharepoint_token, sharepoint_url)

returns the following error:
Error in httr::content(my_content)$d :
$ operator is invalid for atomic vectors

I get the same error with this line of code:
digest_value <- strsplit(httr::content(my_content)$d$GetContextWebInformation$FormDigestValue, ",")[[1]][1]

Add license

Hi there,

Thanks for creating this library, I think it is needed.

Could you please add a license to the repository so that it is clear how it may be used.

Best regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.