cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

'HTTP Error 400 Bad request' while attempting to call 'create_shared_link_with_settings' Dropbox api from vb .net for windows desktop app

'HTTP Error 400 Bad request' while attempting to call 'create_shared_link_with_settings' Dropbox api from vb .net for windows desktop app

requiencat ..
New member | Level 1

Hi. I'm developing a windows desktop app in order to get the dropbox links of the files inside my dropbox directory. I want to use the  'create_shared_link_with_settings' Dropbox api but when I execute POST method I only get vb exception: 'HTTP Error 400 Bad request'.

I'm a basic Dropbox user and developing app for personal use (I don't need to enable additional users). I registered my app and got OAuth2 token.

The data I'm sending is:
{"path":"/Public/MyFile.pdf","settings":{"requested_visibility":"public"}}

In the headers:
"Authorization: Bearer myOAuth2TokenHere"

And the url: "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings"

Here is the vb .net [FrameWork 4.0] code I'm using.

Dim sFormattedFilePath As String = ""
Dim sUri As String = ""
Dim sData As String = ""
Dim sJSON As String = ""
Dim pHeader As WebHeaderCollection = Nothing
Dim pRequest As HttpWebRequest = Nothing
Dim pResponse As HttpWebResponse = Nothing

Try
  sFormattedFilePath = "/Public/MyFile.pdf"

  sData = "{" & Chr(34) & "path" & Chr(34) & ":" & Chr(34) & sFormattedFilePath & Chr(34) & "," & Chr(34) & "settings" & Chr(34) & ":{" & Chr(34) & "requested_visibility" & Chr(34) & ":" & Chr(34) & "public" & Chr(34) & "}}"

  pHeader = New WebHeaderCollection()
  pHeader.Clear()
  pHeader.Add("Authorization: Bearer myOAuth2TokenHere")

  sUri = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings"
  pRequest = DirectCast(HttpWebRequest.Create(sUri), HttpWebRequest)
  pRequest.ContentType = "application/json"
  pRequest.ContentLength = sData.Length
  pRequest.Headers = pHeader
  pRequest.Method = "POST"
  Using s As Stream = pRequest.GetRequestStream()
    s.Write(System.Text.ASCIIEncoding.Default.GetBytes(sData), 0, sData.Length)
  End Using
  pResponse = DirectCast(pRequest.GetResponse(), HttpWebResponse)
  Using sr As New StreamReader(pResponse.GetResponseStream())
    sJSON = sr.ReadToEnd()
  End Using
Catch ex As Exception
   MsgBox(ex.Message)
End Try

If you are wondering:

The content of var sData is
{"path":"/Public/MyFile.pdf","settings":{"requested_visibility":"public"}}

The exception occurs when executing line:
pResponse = DirectCast(pRequest.GetResponse(), HttpWebResponse)

And the message of exception is:
HTTP Error 400 Bad request

I used exactly the same vb.net code when calling 'get_shared_links' api and it worked fine, that's why I was sure the code was correct but when I call 'create_shared_link_with_settings' the code doesn't work.

Any clue of what's happening?? please Help :'(

4 Replies 4

Greg-DB
Dropbox Staff

What's the body of the response? It should contain more useful error information.

requiencat ..
New member | Level 1

My code saves 'the body of the response' into the var: sJSON however, my code crashes before it gets to the line which reads that response. In this case, the one who is throwing the exception is the vb.net compiler.

I don't know if it could be useful but analyzing the information included into the vb.net exception I found this:

Headers = {Transfer-Encoding: chunked  Connection: keep-alive  X-Dropbox-Request-Id: baad501b308ddd5c1310f7af856563fe  Content-Type: text/plain; charset=utf-8  Date: Wed, 16 Mar 2016 19:02:33 GMT  Server: nginx    }

StatusCode = BadRequest {400}
StatusDescription = "Bad Request"

 

requiencat ..
New member | Level 1

Ok, I fixed my code to be able to read 'the body of the response' by performing a cast from the vb exception class. What I've got is this:

"Error in call to API function "sharing/create_shared_link_with_settings": This function requires its argument in the HTTP request body, but your request body is empty."

Greg-DB
Dropbox Staff

That error indicates that your request body was empty, instead of containing the parameters. You'll need to debug the code that makes the request to check why your data isn't getting sent up in the body.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    requiencat .. New member | Level 1
What do Dropbox user levels mean?