-
Notifications
You must be signed in to change notification settings - Fork 0
/
mBox.bas
130 lines (73 loc) · 3.1 KB
/
mBox.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Attribute VB_Name = "mBox"
Sub createfolder(token As String)
'define XML and HTTP components
Dim zipResult As New MSXML2.DOMDocument
Dim zipService As New MSXML2.XMLHTTP
Dim xmlInput As String 'this is the JSON that will form the body of the http request
Dim query As String 'this is the URL, including any parameters
'write the JSON that will go in the body of the http request
xmlInput = "{""name"": ""New Folder"", ""parent"": {""id"": ""0""}}"
'write the query string
query = "https://api.box.com/2.0/folders"
'create HTTP request to query URL
zipService.Open "POST", query, False
'set HTTP request header
zipService.setRequestHeader "Authorization:", "Bearer " & token
'send HTTP request
zipService.send xmlInput
End Sub
Sub main2()
GetFolderContentsBOX "vW7S0DqKNrRwz2x2f0O5q1Em5JZxlpMC", "8479106597"
End Sub
Sub main()
DownloadFile "vW7S0DqKNrRwz2x2f0O5q1Em5JZxlpMC", "72956081037"
End Sub
Sub main3()
createfolder "W9aKuiW64r1EXqSZrxB1uYPicEIa5Ran"
End Sub
Sub UploadBoxFile(ByVal sToken As String)
Dim curlInput As XMLHTTP60
Dim sQuery As String
Dim sXMLInput As String
' need to imitate a form in cURL to complete this one (thats what I managed to get from the cURL documentation on the web
'a google research sugested to use XMLHTTP.6.0. instead of XMLHTTP.
Set curlInput = CreateObject("MSXML2.XMLHTTP.6.0")
' a different location is used for uploading
sQuery = "https://upload.box.com/api/2.0/files/content"
' I think that the mistake is in this string I need to build it a bit differently or somehow indicated the -F parameter when sending
sXMLInput = "attributes={name: ""FullDump.xlsx"", ""parent"": {""id"": ""8479106597""}}" & vbNewLine & "file=D:\Reporting\NewDashboard\Dashboard2.0.xlsx"
curlInput.Open "POST", sQuery, False
curlInput.setRequestHeader "Authorization:", "Bearer " & sToken
curlInput.send sXMLInput
End Sub
Sub GetFolderContentsBOX(ByVal sToken As String, ByVal sFolderID As String)
Dim curlInput As MSXML2.XMLHTTP
Dim curlOutput As MSXML2.DOMDocument
Dim test As Variant
Dim sQuery As String
Dim sResult As String
sQuery = "https://api.box.com/2.0/folders/" & sFolderID & "/items?limit=100&offset=0"
Set curlInput = CreateObject("MSXML2.XMLHTTP")
curlInput.Open "GET", sQuery, False
curlInput.setRequestHeader "Authorization:", "Bearer " & sToken
curlInput.send
Dim doc As Object
Set curlOutput = curlInput.responseXML
sResult = curlInput.responseText
ThisWorkbook.Sheets(1).Cells(1, 1).Value = sResult
End Sub
Sub DownloadFile(ByVal sToken As String, ByVal sFileID As String)
Dim wbBook As Workbook
Dim curlInput As MSXML2.XMLHTTP
Dim curlOutput As MSXML2.DOMDocument
Dim test As Variant
Dim sQuery As String
Dim sResult As String
sQuery = "https://api.box.com/2.0/files/" & sFileID & "/content"
Set curlInput = CreateObject("MSXML2.XMLHTTP")
curlInput.Open "GET", sQuery, False
curlInput.setRequestHeader "Authorization:", "Bearer " & sToken
curlInput.send
sResult = curlInput.responseText
ThisWorkbook.Sheets(1).Cells(1, 1).Value = sResult
End Sub