0

I am trying to upload file in user computer to BOX using API. On GitHub I found this: https://github.com/Tackgnol/VBA-BOX-API/blob/master/mBox.bas

Box Sync and Box Drive are not solution (cannot force user install).

When I printed StatusText I got "Method Not Allowed".

65853643834 is folder id got from URL. h5ntjo525se0tbhwswq8ozpoqsge**** is from Box Dev "Client ID"

enter image description here

Sub UploadFile()
    UploadBoxFile "h5ntjo525se0tbhwswq8ozpoqsge****"
End Sub

Sub UploadBoxFile(ByVal sToken As String)
    Dim curlInput As XMLHTTP60
    Dim sQuery As String
    Dim sXMLInput As String

    Set curlInput = CreateObject("MSXML2.XMLHTTP.6.0")

    sQuery = "https://upload.box.com/api/2.0/files/content"

    sXMLInput = "attributes={name: ""fileSample.txt"", ""parent"": {""id"":         ""65853643834""}}" & vbNewLine & "file=C:\Users\MichalPalko\Downloads\fileSample.txt"

    curlInput.Open "POST", sQuery, False

    curlInput.setRequestHeader "Authorization:", "Bearer " & sToken & 3243
    curlInput.send sXMLInput
    Debug.Print curlInput.StatusText
End Sub

1 Answer 1

0

I'm having the same issue but made some adjustments to your code and am receiving the StatusText response of "Unsupported Media Type".

I feel like I'm so close but stabbing in the dark here. Did you ever figure it out?

My adjusted code is below:

Sub UploadBoxFile(sFilePath As String)
    Dim curlInput 'As XMLHTTP60
    Dim sQuery As String
    Dim sXMLInput As String

    Dim sToken As String
    Dim sFolderID As String
    Const sP As String = """"
    Const sAp As String = "'"

    sQuery = "https://upload.box.com/api/2.0/files/content"
    sToken = "XXXXXXXXXXXXXXXXXXXXXXXXX"     'My Obscured token
    sFolderID = "1234567890"                 'My Obscured FolderID
    sFileName = "TEST File 0001a.txt"

    sXMLInput = "attributes=" & sAp & "{" & sP & "name" & sP & ":" & sP & sFileName _
        & sP & ", " & sP & "parent" & sP & ":{" & sP & "id" & sP & ":" & sP & sFolderID & sP & "}}" & sAp _
        & vbNewLine & "file=" & sFilePath

Debug.Print sXMLInput

    Set curlInput = CreateObject("MSXML2.XMLHTTP.6.0")
    With curlInput
        .Open "POST", sQuery, False
        .setRequestHeader "Authorization:", "Bearer " & sToken
        .send sXMLInput
        Debug.Print .StatusText
    End With
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Hi cows, after all I have changed method. Now I use uploading to box via email (using company SMTP). But if you find out how to go with this, please let us know! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.