cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right 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: 

Obtaining shared link from VBA (API v2) - 409 Conflict

Obtaining shared link from VBA (API v2) - 409 Conflict

Bob D.20
New member | Level 1

I have the following code which I modified slightly from this link. The return is a 409 Conflict error. I believe the issue lies in how I'm structuring the path string, but I admit to this being well beyond my limited VBA programming skills (more of "mosh thing together until they work skills."

Can someone provide some direction that might help?

    Dim req As MSXML2.ServerXMLHTTP60
    Set req = New MSXML2.ServerXMLHTTP60
    Dim arg As String
    Dim filename As String
    Dim path As String
    Dim Result As String
    
    path = "Desktop Work File"
    filename = "33602DOX.pdf"
    
    arg = "{""path"": ""/" & filename & """}"
    req.Open "POST", "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings", False
    req.setRequestHeader "Authorization", "Bearer XXXXXXXXXX"
    req.setRequestHeader "Content-Type", "application/json"
    req.Send arg
    If req.Status = 200 Then
        Debug.Print req.responseText
    Else
        MsgBox req.Status & ": " & req.StatusText
        Debug.Print req.responseText
    End If

8 Replies 8

Greg-DB
Dropbox Staff

What's in the response body? It should contain a specific error indicating the issue.

Bob D.20
New member | Level 1

This is what is showing up in the Immediate window of my VBA editor after I accept the 409 message:

{"error_summary": "path/not_found/..", "error": {".tag": "path", "path": {".tag": "not_found"}}}

That seems to substantiate my thought that the path structure is wrong.

Greg-DB
Dropbox Staff

That's correct, a path/not_found error from /2/sharing/create_shared_link_with_settings indicates "there is nothing at the given path". 

You gave the path "/33602DOX.pdf", so there must not be anything at that path in the account you're calling for. For example, if the file is inside a folder called "Documents", you should supply the path "/Documents/33602DOX.pdf".

(I also don't see you using your "path" variable, with value "Desktop Work File". Should that be part of the path?)

Bob D.20
New member | Level 1

The file does exist at Desktop Work File/33602DOX.pdf.

In the code line "arg = "{"path": "/" & filename & "}", I assumed path to be the folder string, and filename to be the document string. However, upon further review of the API documentation, I see that is a misunderstanding. I worked the script a bit, but still produce the same error.

Here is the sample arg line from the API doc: {"path": "/Prime_Numbers.txt"}

Here is the line I am passing in my arg: {"path": "/Desktop Work File/33602DOX.pdf"}

I'm not seeing why my arg is not working...it appears functionally identical to the sample, but clearly is not.

Please understand - I am not a programmer or IT specialist; this is a tool I am trying to use to improve my workflow, and I do not fully understand it. Can you help me understand how I should be structuring the arg message? I realize VBA may not be your forte, but if I can come to an understanding on the proper structure that I'm supposed to be sending, I should be able to make it work in VBA. (I've reviewed the API documentation, but I don't understand a lot of that without full-blown samples to experiment with - which is where the original script I linked to comes in....)

Thank you!

Greg-DB
Dropbox Staff

When supplying the path argument for the file, you do need to supply the full path, including any parent folders. In the sample, the file was presumed to be in the root, but for your case you would need to supply the full "/Desktop Work File/33602DOX.pdf".

Your original code was:

arg = "{"path": "/" & filename & "}"

So, that would need to be something like:

arg = "{"path": "/" & path & "/" & filename & "}"

That should work out to what you have in your followup:

{"path": "/Desktop Work File/33602DOX.pdf"}

Is that also giving the same exact "path/not_found" error? (There are other kinds of path errors.) You should also make sure you're connected to the account you intend.

You can use /2/users/get_current_account to check the account. You can use /2/files/list_folder[/continue] to list the contents of a folder. The API Explorer is also a good way to try out the API.

Bob D.20
New member | Level 1

Thank you! The clue was in "make sure you're connected to the account you intend." I was, but my app was set for it's own folder, not all of my DB account!

Rectified that, and completed as successful share link retrieval!

For anyone that needs it, here's the final script:

    Dim req As MSXML2.ServerXMLHTTP60
    Set req = New MSXML2.ServerXMLHTTP60
    Dim arg As String
    Dim filename As String
    Dim path As String
    Dim Result As String

    path = "Desktop Work File"
    filename = "33603DOX.pdf"
    
    arg = "{"path": "/" & path & "/" & filename & "}"
   
    req.Open "POST", "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings", False
    req.setRequestHeader "Authorization", "Bearer <redacted>"
    req.setRequestHeader "Content-Type", "application/json"
    req.Send arg
    If req.Status = 200 Then
        Debug.Print req.responseText
    Else
        MsgBox req.Status & ": " & req.StatusText
        Debug.Print req.responseText
    End If

Greg-DB
Dropbox Staff

Bob, I redacted that access token for you, but you should revoke it to be safe. 

Bob D.20
New member | Level 1

Thank you...can't believe I forgot to take that out! Taking your advice right now.

Need more support?
Who's talking

Top contributors to this post

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