3

EDIT 1

Changing Content-Type:application/json to Content-Type:multipart/form as suggested in the comments solved the 415 error. My Script looks like this now:

Set oShell = CreateObject ("WScript.Shell")
oShell.run "cmd.exe /K cd C:\Users\Desktop\APITests\ & curl https://upload.box.com/api/2.0/files/content -H ""Authorization: Bearer myToken"" -H ""Content-Type:multipart/form"" -X POST -F attributes=""{""name"":""C:\Users\mgros8\Desktop\APITests\Query.txt"", ""parent"":{""id"":""82850162833""}}"" -F file=@C:\Users\Desktop\APITests\Query.txt -k --verbose"

and the response I get from my call is:

{"code":"bad_request","help_url":"http://developers.box.com/docs/#errors","status":400,"message":"API upload did not contain a file part","type":"error"}* Connection #0 to host upload.box.com left intact

So I believe that my filepath is still not good as it is unable to find it..

Original Question

I am trying to create a script to automatically upload certain files to a given folder in Box. However, upon running my script I get the 415 error.

I have tried multiple solutions online but nothing is working as for now.

curl https://upload.box.com/api/2.0/files/content -H "Authorization: Bearer dummyToken" -H "Content-Type:application/json" -X POST -F attributes="{"name":"YDE-3946332.pdf", "parent":{"id":"82850162833"}}" -F file=@"C:\Users\dummyFolder\YDE-3946332.pdf" -k --verbose

The error log I am getting is the following:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 185.235.236.226:443...
* TCP_NODELAY set
* Connected to upload.box.com (185.235.236.226) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=US; ST=California; L=Redwood City; O=Box, Inc.; CN=*.box.com
*  start date: Feb  7 00:00:00 2018 GMT
*  expire date: Nov 28 12:00:00 2020 GMT
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> POST /api/2.0/files/content HTTP/1.1
> Host: upload.box.com
> User-Agent: curl/7.65.3
> Accept: */*
> Authorization: Bearer dummyToken
> Content-Length: 62461
> Content-Type: application/json; boundary=------------------------7e98acd45cf91cff
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 415 Unsupported Media Type
< Date: Thu, 25 Jul 2019 10:39:04 GMT
< Content-Type: text/html; charset=UTF-8
< Content-Length: 0
< Connection: keep-alive
< Strict-Transport-Security: max-age=31536000
<
* Connection #0 to host upload.box.com left intact

Is there anbody facing the same situation and can identify why my filename/path is not parsed correctly?

mikegross
  • 1,674
  • 2
  • 12
  • 27
  • This isn't a VBScript issue, the problem is with the `curl` command line call if there is even a problem, based on the POST you are making to upload the file the server is responding with HTTP 415. – user692942 Jul 25 '19 at 11:14
  • I know. It is a box-api problem – mikegross Jul 25 '19 at 11:21
  • Think the problem [lies here](https://developer.box.com/reference#upload-a-file) - *"This API uses the **[multipart post](http://hc.apache.org/httpclient-3.x/methods/multipartpost.html)** method to complete all upload tasks."*. You need to look at [Using curl to upload POST data with files](//stackoverflow.com/a/12667839). Try changing the `Content-Type` to `multipart/form` not `application/json`. – user692942 Jul 25 '19 at 11:29
  • I guess this solves the initial issue. Now I am getting a more insightful error: {"code":"bad_request","help_url":"http://developers.box.com/docs/#errors","status":400,"message":"API upload did not contain a file part","type":"error"} – mikegross Jul 25 '19 at 11:38

0 Answers0