Skip to main content
Question

Accessing and downloading files of enterprise shared folders via API

  • November 13, 2024
  • 0 replies
  • 37 views

Forum|alt.badge.img

Hello everyone,

At work, I am often shared a box.com link and I have to download the files in those shared link as part of my day to day work. So I need to open the link in a browser, select the files and then download them.

Due to the number of files I need to process, I am trying to automate these steps. Using AI tools, I have managed to come up with a VBA code that would download publicly shared files (For reference I am not allowed to install other programming language, so VBA is my only option).

The problem is that it only works for publicly shared files, my company use an enterprise version of box.com and the url shared are like this:

https://COMPANYNAME.ent.box.com/s/RANDOMNUMBERS&LETTERS
 

The file links are then found and they are:

https://COMPANYNAME.ent.box.com/s/RANDOMNUMBERS&LETTERS/file/FILEID
 

Is there any way I can modify it to make it work with the API.

 

If anyone is interested, I am trying the following code, I just cant download the correct file
 

Sub DownloadFileFromBox()
    Dim http As Object
    Dim url As String
    Dim filePath As String

    ' Set the URL of the file you want to download
    url = "https://COMPANYNAME.ent.box.com/s/RANDOMNUMBERS&LETTERS/file/FILEID"

    ' Set the path where you want to save the downloaded file
    filePath = Environ("USERPROFILE") & "\Downloads\test"

    ' Create an XMLHTTP object
    Set http = CreateObject("MSXML2.XMLHTTP")

    ' Open the URL
    http.Open "GET", url, False
    http.Send

    ' Save the file to the specified path
    If http.Status = 200 Then
        Dim stream As Object
        Set stream = CreateObject("ADODB.Stream")
        stream.Open
        stream.Type = 1 ' adTypeBinary
        stream.Write http.responseBody
        stream.SaveToFile filePath, 2 ' adSaveCreateOverWrite
        stream.Close
        MsgBox "File downloaded successfully!"
    Else
        MsgBox "Failed to download file. Status: " & http.Status
    End If

    ' Clean up
    Set http = Nothing
End Sub

 

0 replies

Be the first to reply!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings