Skip to contents

Note, this vignette is pre-computed to utilize the Microsoft Graph login that is only available locally to me as a logged in SharePoint user. As a result, it is possible this documentation may be outdated or incomplete.

This is a folder URL. It is a Shared link where people with existing access can use the link.

dir_url <- "https://bmore.sharepoint.com/:f:/r/sites/DOP-CPR/Shared%20Documents/INSPIRE%20Program%20%F0%9F%8F%AB%F0%9F%9A%B8%F0%9F%8C%B3?csf=1&web=1&e=W5dbYz"

There are a bunch of different types of URLs that SharePoint uses so they don’t all work with this package yet. You can parse a URL into smaller parts:

sp_url_parse(dir_url)
#> $base_url
#> [1] "https://bmore.sharepoint.com"
#> 
#> $tenant
#> [1] "bmore"
#> 
#> $path
#> [1] "/:f:/r/sites/DOP-CPR/Shared Documents/INSPIRE Program 🏫🚸🌳"
#> 
#> $url_type
#> [1] "f"
#> 
#> $permissions
#> [1] "r"
#> 
#> $site_name
#> [1] "DOP-CPR"
#> 
#> $file_path
#> [1] "/INSPIRE Program 🏫🚸🌳"
#> 
#> $drive_name
#> [1] "Documents"
#> 
#> $item_id
#> NULL
#> 
#> $csf
#> [1] "1"
#> 
#> $web
#> [1] "1"
#> 
#> $e
#> [1] "W5dbYz"
#> 
#> $site_url
#> [1] "https://bmore.sharepoint.com/sites/DOP-CPR"

These parts can be used as the path, site_url, and other parameters can be used to get sites, drives, lists, and items from SharePoint:

get_sp_site(dir_url)
#> Loading Microsoft Graph login for default tenant
#> <Sharepoint site 'DOP-CPR'>
#>   directory id: bmore.sharepoint.com,67aec41a-38f7-471f-8409-a71c3bece3a0,f506465a-e433-42ae-a52b-cb7130b77d59 
#>   web link: https://bmore.sharepoint.com/sites/DOP-CPR 
#>   description:   
#> ---
#>   Methods:
#>     delete, do_operation, get_drive,
#>     get_group, get_list, get_list_pager,
#>     get_lists, list_drives, list_subsites,
#>     sync_fields, update

get_sp_drive(dir_url)
#> Loading Microsoft Graph login for default tenant
#> <Document library 'Documents'>
#>   directory id: b!GsSuZ_c4H0eECaccO-zjoFpGBvUz5K5CpSvLcTC3fVkj4DsIzWYXTaCOSKIsJAdy 
#>   web link: https://bmore.sharepoint.com/sites/DOP-CPR/Shared%20Documents 
#>   description:  
#> ---
#>   Methods:
#>     copy_item, create_folder,
#>     create_share_link, delete,
#>     delete_item, do_operation,
#>     download_file, download_folder,
#>     get_item, get_item_properties,
#>     get_list_pager, list_files,
#>     list_items, list_shared_files,
#>     list_shared_items, load_dataframe,
#>     load_rdata, load_rds, move_item,
#>     open_item, save_dataframe, save_rdata,
#>     save_rds, set_item_properties,
#>     sync_fields, update, upload_file,
#>     upload_folder

With a directory URL, you can get a list of files:

dir_info <- sp_dir_info(dir_url)
#> Loading Microsoft Graph login for default tenant

dir_info
#>                                                                                  name
#> 1                                         INSPIRE Program 🏫🚸🌳/2024 SMART Goal Docs
#> 2                                INSPIRE Program 🏫🚸🌳/INSPIRE Plan Histories (CHAP)
#> 3                                     INSPIRE Program 🏫🚸🌳/INSPIRE Plans Adopted βœ…
#> 4                                  INSPIRE Program 🏫🚸🌳/INSPIRE Plans In Progress ✏️
#> 5                                        INSPIRE Program 🏫🚸🌳/INSPIRE Program Admin
#> 6                                                       INSPIRE Program 🏫🚸🌳/Photos
#> 7                                                   INSPIRE Program 🏫🚸🌳/References
#> 8                               INSPIRE Program 🏫🚸🌳/_2021_Planner+School List.xlsx
#> 9  INSPIRE Program 🏫🚸🌳/2023-05-17-dhcd-code-enforcement_recommendation-review.docx
#> 10                                           INSPIRE Program 🏫🚸🌳/Budget scrap.xlsx
#> 11                              INSPIRE Program 🏫🚸🌳/Historical Assessment Doc.docx
#> 12                  INSPIRE Program 🏫🚸🌳/INSPIRE Community Engagement Notebook.xlsx
#> 13                INSPIRE Program 🏫🚸🌳/INSPIRE Comprehensive Plan Contribution.docx
#> 14                               INSPIRE Program 🏫🚸🌳/INSPIRE DOP Website Copy.docx
#> 15                            INSPIRE Program 🏫🚸🌳/INSPIRE Master Contact List.xlsx
#> 16                         INSPIRE Program 🏫🚸🌳/INSPIRE Plan Timelines 2021_08.docx
#> 17                       INSPIRE Program 🏫🚸🌳/INSPIRE Planning Guide - Updated.docx
#> 18                                             INSPIRE Program 🏫🚸🌳/INSPIRE Program
#> 19                               INSPIRE Program 🏫🚸🌳/INSPIRE Program Calendar.xlsx
#> 20                                INSPIRE Program 🏫🚸🌳/INSPIRE Rec tables 2023.xlsx
#> 21                                 INSPIRE Program 🏫🚸🌳/INSPIRE Workflow DRAFT.docx
#> 22           INSPIRE Program 🏫🚸🌳/Middle Neighborhoods INSPIRE Assessment Plan.docx
#> 23                         INSPIRE Program 🏫🚸🌳/Preparing for a Community Walk.docx
#> 24                                    INSPIRE Program 🏫🚸🌳/Test Planner Import.xlsx
#>       size isdir                                 id
#> 1        0  TRUE 01EK4O46SKWLCBFTE2HRDYDHP5IJNW2OIU
#> 2  427.82M  TRUE 01EK4O46W2BVSN34MWIJCZO45SX2RIMVRR
#> 3   125.1M  TRUE 01EK4O46TWHR6QA77FQRAK3TFSP5Z5WGUV
#> 4    2.27G  TRUE 01EK4O46XRFXKSJ4MSCVHIXD3E2JCCGZ4Y
#> 5  903.26M  TRUE 01EK4O46TNZAXB5BWALZEJF4Y5NCBZPPKB
#> 6  448.55M  TRUE 01EK4O46XP2EGVNL5XUNC2GGCWCXQOCBR6
#> 7  150.88M  TRUE 01EK4O46S5WYIRFXP42ZBZ3XJBCAX5WRD2
#> 8   43.01K FALSE 01EK4O46S42QAM2K6FSBAZPBQOS4VBT3YI
#> 9   29.88K FALSE 01EK4O46VKEMUM7LD3YNHJ5IA67DXT6K42
#> 10   15.3K FALSE 01EK4O46XFZKGJN3S4AVBYMIEB5OQTG3K7
#> 11  20.97K FALSE 01EK4O46RLN3E7BWYST5GIKRJAVB7VDI3N
#> 12   23.4K FALSE 01EK4O46TFJABPEPMTS5CINCRI7LRAN554
#> 13  29.06K FALSE 01EK4O46UOLVTZZANSPJHZ3ICJBFFGO7P5
#> 14  13.32M FALSE 01EK4O46VQJZ4S7SZ2EFB3N267A4U67XVG
#> 15  29.34K FALSE 01EK4O46VTPF5MRFPSYZHYQ2YJN5C3A4PP
#> 16  32.51K FALSE 01EK4O46RKC2EBRPKIVRC34NZGU2XDUGXF
#> 17  63.33K FALSE 01EK4O46RYX55LJ6VAAZFINIOB2XF2UXLF
#> 18   2.03M  TRUE 01EK4O46XVR7PESI3HXZCJF2UDW6YZ53DD
#> 19  23.14K FALSE 01EK4O46QCKIPTO4QQG5AY3V422XIJYQHZ
#> 20  26.21K FALSE 01EK4O46S6CMHTD2335VFZS6VVEDMWRHJN
#> 21   24.2K FALSE 01EK4O46UK2YTRIADBPBEIKM5ODDWX76JO
#> 22  25.49K FALSE 01EK4O46TS3YMEYF4KTBF34FWZQ5ER7SF7
#> 23  22.73K FALSE 01EK4O46W4HZJORDO57VBL6YIFK3VTDZST
#> 24  15.17K FALSE 01EK4O46XDUXMFXPTV4NAICXGZ2YGAYAJU
#>         type
#> 1  directory
#> 2  directory
#> 3  directory
#> 4  directory
#> 5  directory
#> 6  directory
#> 7  directory
#> 8       file
#> 9       file
#> 10      file
#> 11      file
#> 12      file
#> 13      file
#> 14      file
#> 15      file
#> 16      file
#> 17      file
#> 18 directory
#> 19      file
#> 20      file
#> 21      file
#> 22      file
#> 23      file
#> 24      file

You can use the same URL to get a character vector of file names:

sp_dir_ls(dir_url)
#> Loading Microsoft Graph login for default tenant
#>  [1] "2024 SMART Goal Docs"                                       
#>  [2] "INSPIRE Plan Histories (CHAP)"                              
#>  [3] "INSPIRE Plans Adopted βœ…"                                   
#>  [4] "INSPIRE Plans In Progress ✏️"                                
#>  [5] "INSPIRE Program Admin"                                      
#>  [6] "Photos"                                                     
#>  [7] "References"                                                 
#>  [8] "_2021_Planner+School List.xlsx"                             
#>  [9] "2023-05-17-dhcd-code-enforcement_recommendation-review.docx"
#> [10] "Budget scrap.xlsx"                                          
#> [11] "Historical Assessment Doc.docx"                             
#> [12] "INSPIRE Community Engagement Notebook.xlsx"                 
#> [13] "INSPIRE Comprehensive Plan Contribution.docx"               
#> [14] "INSPIRE DOP Website Copy.docx"                              
#> [15] "INSPIRE Master Contact List.xlsx"                           
#> [16] "INSPIRE Plan Timelines 2021_08.docx"                        
#> [17] "INSPIRE Planning Guide - Updated.docx"                      
#> [18] "INSPIRE Program"                                            
#> [19] "INSPIRE Program Calendar.xlsx"                              
#> [20] "INSPIRE Rec tables 2023.xlsx"                               
#> [21] "INSPIRE Workflow DRAFT.docx"                                
#> [22] "Middle Neighborhoods INSPIRE Assessment Plan.docx"          
#> [23] "Preparing for a Community Walk.docx"                        
#> [24] "Test Planner Import.xlsx"

But you can’t use that URL to get a list:

get_sp_list(dir_url)
#> Error in `call_match()`:
#> ! `fn` must be supplied.

SharePoint lists have two different styles of URLs (that I’ve seen). This one works:

list_url <- "https://bmore.sharepoint.com/:l:/r/sites/MayorsOffice-DataGovernance/Lists/Data%20Governance%20Progress%20Tracker?e=0P1fFX"

get_sp_list(list_url)
#> Loading Microsoft Graph login for default tenant
#> Loading Microsoft Graph login for default tenant
#> 
β„Ή Getting list from SharePoint

βœ” Getting list from SharePoint [119ms]
#> <Sharepoint list 'Data Governance Progress Tracker'>
#>   directory id: 5c21d327-7016-4b69-ae0d-dc95059a876c 
#>   web link: https://bmore.sharepoint.com/sites/MayorsOffice-DataGovernance/Lists/Data%20Governance%20Progress%20Tracker 
#>   description:  
#> ---
#>   Methods:
#>     bulk_import, create_item, delete,
#>     delete_item, do_operation,
#>     get_column_info, get_item,
#>     get_list_pager, list_items,
#>     sync_fields, update, update_item

As of January 2024, this one also works:

"https://bmore.sharepoint.com/sites/MayorsOffice-DataGovernance/Lists/Data%20Governance%20Progress%20Tracker/AllItems.aspx?env=WebViewList"
#> [1] "https://bmore.sharepoint.com/sites/MayorsOffice-DataGovernance/Lists/Data%20Governance%20Progress%20Tracker/AllItems.aspx?env=WebViewList"

Shared URLs for files work with get_sp_item() and get_sp_item_properties():

file_url <- "https://bmore.sharepoint.com/:w:/r/sites/DOP-CPR/Shared%20Documents/INSPIRE%20Program%20%F0%9F%8F%AB%F0%9F%9A%B8%F0%9F%8C%B3/INSPIRE%20Plans%20In%20Progress%20%E2%9C%8F%EF%B8%8F/Govans%20ES/Govans%20Final%20Planning%20Document%20and%20related%20materials/Govans%20INSPIRE%20Plan%20-%20Final%20draft%20before%20layout.docx?d=w3408fbc67fa2462187409eb240eb4df2&csf=1&web=1&e=4dcgze"

get_sp_item(file_url)
#> Loading Microsoft Graph login for default tenant
#> <Drive item 'Govans INSPIRE Plan - Final draft before layout.docx'>
#>   directory id: 01EK4O46WG7MEDJIT7EFDIOQE6WJAOWTPS 
#>   web link: https://bmore.sharepoint.com/sites/DOP-CPR/_layouts/15/Doc.aspx?sourcedoc=%7B3408FBC6-7FA2-4621-8740-9EB240EB4DF2%7D&file=Govans%20INSPIRE%20Plan%20-%20Final%20draft%20before%20layout.docx&action=default&mobileredirect=true 
#>   type: file 
#> ---
#>   Methods:
#>     copy, create_folder,
#>     create_share_link, delete,
#>     do_operation, download, get_item,
#>     get_list_pager, get_parent_folder,
#>     get_path, is_folder, list_files,
#>     list_items, load_dataframe,
#>     load_rdata, load_rds, move, open,
#>     save_dataframe, save_rdata, save_rds,
#>     sync_fields, update, upload

Or you can also use a document URL (as long as the default library is set to match the document library of the supplied URL):

document_url <- "https://bmore.sharepoint.com/:w:/r/sites/DOP-CPR/_layouts/15/Doc.aspx?sourcedoc=%7B3408FBC6-7FA2-4621-8740-9EB240EB4DF2%7D&file=Govans%20INSPIRE%20Plan%20-%20Final%20draft%20before%20layout.docx&action=default&mobileredirect=true"

get_sp_item(document_url)
#> Loading Microsoft Graph login for default tenant
#> <Drive item 'Govans INSPIRE Plan - Final draft before layout.docx'>
#>   directory id: 01EK4O46WG7MEDJIT7EFDIOQE6WJAOWTPS 
#>   web link: https://bmore.sharepoint.com/sites/DOP-CPR/_layouts/15/Doc.aspx?sourcedoc=%7B3408FBC6-7FA2-4621-8740-9EB240EB4DF2%7D&file=Govans%20INSPIRE%20Plan%20-%20Final%20draft%20before%20layout.docx&action=default&mobileredirect=true 
#>   type: file 
#> ---
#>   Methods:
#>     copy, create_folder,
#>     create_share_link, delete,
#>     do_operation, download, get_item,
#>     get_list_pager, get_parent_folder,
#>     get_path, is_folder, list_files,
#>     list_items, load_dataframe,
#>     load_rdata, load_rds, move, open,
#>     save_dataframe, save_rdata, save_rds,
#>     sync_fields, update, upload