# File upload using VBA, JSON options error

**URL:** <https://community.hubspot.com/t/file-upload-using-vba-json-options-error/59439>\
**Category:** APIs & Integrations\
**Created:** [June 21, 2022, 12:04pm UTC](https://community.hubspot.com/t/file-upload-using-vba-json-options-error/59439 "2022-06-21T12:04:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NLewis3](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@NLewis3](https://community.hubspot.com/u/NLewis3)\
**Post date:** [June 21, 2022, 12:04pm UTC](https://community.hubspot.com/t/file-upload-using-vba-json-options-error/59439/1 "2022-06-21T12:04:59Z")

</div>

Hi, I’m looking for help file with upload through the API from VBA (using MS Access).

I can upload using Postman, however struggling to replicate this in VB - getting the following error:

{“status”:“error”,“message”:“Invalid json Content-Disposition: form-data; name=\“options\”\r\nContent-Type: application/json\r\n{\“access\”:\“PRIVATE\”} for options string. Make sure required field \“access\” is set.”,“correlationId”:“b7a1d6b2-83c5-41b0-847a-acd007595745”}

code I’m using to POST is:

'prepare body  
sPostBody = “--” & STR\_BOUNDARY & vbCrLf & \_  
“Content-Disposition: form-data; name=”“file”“; filename=”“” & Mid$(sFileName, InStrRev(sFileName, “\”) + 1) & “”“” & vbCrLf & \_  
“Content-Type: application/octet-stream” & vbCrLf & \_  
sPostData & vbCrLf & \_  
“--” & STR\_BOUNDARY & vbCrLf & \_  
“Content-Disposition: form-data; name=”“folderPath”“” & vbCrLf & \_  
“Quotes” & vbCrLf & \_  
“--” & STR\_BOUNDARY & vbCrLf & \_  
“Content-Disposition: form-data; name=”“options”“” & vbCrLf & \_  
“Content-Type: application/json” & vbCrLf & \_  
“{”“access”“:”“PRIVATE”“}” & vbCrLf & \_  
“--” & STR\_BOUNDARY & “--”  
'post  
With CreateObject(“Msxml2.ServerXMLHTTP.6.0”)  
.Open “POST”, sUrl, bAsync  
.setRequestHeader “Content-Type”, “multipart/form-data; boundary=” & STR\_BOUNDARY  
.setRequestHeader “Authorization”, sAuth  
.send pvToByteArray(sPostBody)

Please note I am not programmer so is quite possible I am missing something very basic - any help appreciated.

Thanks

Nick

---

<div class="post-metadata">

**Author:** ![dramaCool](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dramaCool](https://community.hubspot.com/u/dramaCool)\
**Post date:** [June 21, 2022, 7:27pm UTC](https://community.hubspot.com/t/file-upload-using-vba-json-options-error/59439/2 "2022-06-21T19:27:35Z")

</div>

good work keep it up . [dramacool](https://dramacool.no/)

---

<div class="post-metadata">

**Author:** ![NLewis3](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@NLewis3](https://community.hubspot.com/u/NLewis3)\
**Post date:** [June 22, 2022, 4:51pm UTC](https://community.hubspot.com/t/file-upload-using-vba-json-options-error/59439/3 "2022-06-22T16:51:09Z")

</div>

Thanks, it but it would be even better if worked.

I don’t know why the API is not accepting json options string.

---

<div class="post-metadata">

**Author:** ![NLewis3](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@NLewis3](https://community.hubspot.com/u/NLewis3)\
**Post date:** [June 24, 2022, 6:13pm UTC](https://community.hubspot.com/t/file-upload-using-vba-json-options-error/59439/4 "2022-06-24T18:13:34Z")

</div>

Worked it out myself. Needed an extra vbcrlf within each datapart. Working body string is:

sPostBody = “--” & STR\_BOUNDARY & vbCrLf & \_  
“Content-Disposition: form-data; name=”“file”“; filename=”“” & Mid$(sFileName, InStrRev(sFileName, “\”) + 1) & “”“” & vbCrLf & \_  
“Content-Type: application/octet-stream” & vbCrLf & vbCrLf & \_  
sPostData & vbCrLf & \_  
“--” & STR\_BOUNDARY & vbCrLf & \_  
“Content-Disposition: form-data; name=”“folderPath”“” & vbCrLf & vbCrLf & \_  
“Quotes” & vbCrLf & \_  
“--” & STR\_BOUNDARY & vbCrLf & \_  
“Content-Disposition: form-data; name=”“options”“” & vbCrLf & \_  
“Content-Type: application/json” & vbCrLf & vbCrLf & \_  
“{”“access”“:”“PRIVATE”“}” & vbCrLf & \_  
“--” & STR\_BOUNDARY & “--”
