Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing sharepoint in R with windows authentication

I am trying to read data from my company intranet sharepoint.

require(httr)
url <- "http://<domain>/<path>/_vti_bin/ListData.svc/<something>"
r <- GET(url)

The problem is, access to Sharepoint uses Windows authentication. The above, expectedly, gave me 401 Unauthorized error.

How can I incorporate my windows authentication into the request in R, without typing my credential in clear text in the GET parameter? (using authenticate() with my credentials do work).

like image 826
Ricky Avatar asked May 07 '15 04:05

Ricky


2 Answers

authenticate() is the right function to use, but you need to change the input as shown below:

require(httr)
url <- "http://<domain>/<path>/_vti_bin/ListData.svc/<something>"
r <- GET(url, authenticate("username","password",type="any"))

I'm not sure which specific type works, but I was able to establish a session using any. I found the solution in the httr package documentation.

https://cran.r-project.org/web/packages/httr/httr.pdf

like image 106
Mark Druffel Avatar answered Oct 23 '22 05:10

Mark Druffel


Get your site-id as outlined here. Get your list-id as outlined here. If you need to expand any list items, check this out.

And to make sure you don't pull your hair out and go bald like me, make sure that your item-level permissions for read access in the SharePoint site are set to "Read all items" (here's a reference).

library(AzureGraph)

gr <- create_graph_login()
me <- gr$get_user("me")
url <- "https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items"
r <- call_graph_url(me$token, url, http_verb = c("GET"))
like image 42
bm5tev3 Avatar answered Oct 23 '22 04:10

bm5tev3