Help with using the Microsoft365R package

Hello all,

I was wondering if anyone has experience using the Microsoft365R package, especially using it to work with Excel data.

My goal is to pull data from an Excel file on Onedrive, append a new row to the end, and re-upload the file to overwrite the old one. I'm was able to bring down the file and read the data fine, however I don't know how to use the "upload_file" function. My attempts at an upload result in this output:

OneDriveBusiness$upload_file(src = newExcel, dest = "Documents")

Error in process_response(res, match.arg(http_status_handler), simplify) : 
  Conflict (HTTP 409). Failed to complete operation. Message:
Cannot create an upload session on a folder.

Any help would be appreciated!

Hi @KCoder2613 , thank you for your question.

I have little experience with {Microsoft365R} but have used it occaisionally, so bear with me.

I've had a little play around and here's what I've been able to do:

# get a reference to my OneDrive
od <- Microsoft365R::get_business_onedrive()

# upload a file from my project directory to OneDrive
od$upload_file(
  src = here::here('data', 'test', 'test_upload.xlsx'),
  dest = 'test_upload_whoop.xlsx'
)

# upload the same file to a folder called 'Documents'
od$upload_file(
  src = here::here('data', 'test', 'test_upload.xlsx'),
  dest = 'Documents/test_upload_whoop.xlsx'
)

Both of the above work as expected. However, if I specify only 'Documents' as the dest I get the following:

# set dest as 'Documents' - results in error
od$upload_file(
  src = here::here('data', 'test', 'test_upload.xlsx'),
  dest = 'Documents'
)
Error in process_response(res, match.arg(http_status_handler), simplify) : 
  Conflict (HTTP 409). Failed to complete operation. Message:
Cannot create an upload session on a folder.

So I guess the answer is to specify a file path for your dest along the lines of Documents/newExcel.xlsx. Does this work for you?

1 Like

Microsoft 365 – Solutions maybe useful here as well.

1 Like

Hello @craig.parylo, thank you for your response.

This implementation worked! I did not realize I had to include the actual file name in the source and destination.

I wanted the file destination to go to the root folder so I was confused if I needed a "/" or some form of location name in the parameter, but apparently not. Thanks again!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.