Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

cristrod817's avatar
cristrod817
Explorer | Level 3
3 years ago
Solved

Dropbox's code example for sharing a file link in Python not working

#Python code provided by Dropbox
import requests
import json

headers = {
    "Authorization": "Bearer append-current-token"
"Content-Type": "application/json"
}
data = {
    "path": "/baby dream/Cris Rodriguez/10yrsZ.tif"
}

r = requests.post(url, headers=headers, data=json.dumps(data))
print(r.text)
 
I am getting this error text: 400
 
Error in call to API function "sharing/get_shared_link_metadata":
This function requires its argument in the HTTP request body, but your request body is empty.
 
This is the default code provided by Dropbox which I am trying to implement but to no avail.
I've done my research to no avail.  Need help desperately.
 
I am using VS Code as my editor, Windows 10 latest version, Python 3.10.10



  • cristrod817, as Greg pointed out, 'url' parameter is missing in your request and of course, the error message, you're receiving, notes the same. Take a look once again in the link you post above. There are 3 parameters - 1 mandatory and 2 optional. You have put only one of the optional params. 🙂 Where is the link you want to check metadata for? That's it.

10 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    3 years ago

    Can you let me know where you found or received this code so I can check on that?

     

    In any case, is this the actual/exact code you're running? When I plug in an access token, and add the missing "," in the 'headers' object that otherwise causes a SyntaxError, I actually get the different error "Error in call to API function "sharing/get_shared_link_metadata": request body: missing required field 'url'" which would be expected in this case for this code, as the /2/sharing/get_shared_link_metadata endpoint requires a 'url' parameter.

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    3 years ago

    cristrod817, as Greg pointed out, 'url' parameter is missing in your request and of course, the error message, you're receiving, notes the same. Take a look once again in the link you post above. There are 3 parameters - 1 mandatory and 2 optional. You have put only one of the optional params. 🙂 Where is the link you want to check metadata for? That's it.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    3 years ago

    Thanks for clarifying! That's correct, the /2/sharing/get_shared_link_metadata endpoint does require the 'url' parameter. That endpoint is a way to get information about a Dropbox shared link, so you need to include the Dropbox shared link in the call. The 'path' parameter can additionally be supplied to request information about a particular item relative to the folder, if the shared link itself is for a folder.

     

    In my testing, the API v2 Explorer "Python request (requests library)" option for that endpoint is correctly including the 'url' parameter, and likewise I wasn't able to reproduce the original "request body is empty" error with this code, so it sounds like you were using a modified version of that code.

     

    Anyway, it looks like you've got this sorted out now, but let us know if you need help with anything else.

  • cristrod817's avatar
    cristrod817
    Explorer | Level 3
    3 years ago

    Ok, I have updated the code to include the url parameter within the data = statement.  Now I am getting the same error as the default code provided by Dropbox.  I have included a print statement at the end of the code so I can see the response which is:

     

    {"error_summary": "shared_link_not_found/..", "error": {".tag": "shared_link_not_found"}}

    The code is identical to that

     

    Here's my updated code:

    import requests
    import json


    headers = {
        "Authorization": "Bearer sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx removed",
        "Content-Type": "application/json"
    }

    data = {
        "path": "/Cris Rodriguez/Baby Dream CSV/Beach Vibes (GO) 6x8 WEB.jpg"
    }

    r = requests.post(url, headers=headers, data=json.dumps(data))
    print(r.text)Default code by DropboxMy Python CodeError returned by Dropbox Code
  • Здравко's avatar
    Здравко
    Legendary | Level 20
    3 years ago

    cristrod817, where is your shared link? 🙃 Did you forget what you're trying achieve - to get shared link metadata? You have to provide a shared link with that url field, not just some URL! What actually do you expect to see as metadata for the 'link' you provided? 😁

    Hope this gives the next step.

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    3 years ago

    Ha ha.. 😁 you are trying to evaluate an existing link, not to create a new link. 😉 If you want to create such link take a look here. 😉

    Hope this helps.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    3 years ago

    cristrod817 Здравко is correct; /2/sharing/get_shared_link_metadata is for getting information about an existing shared link that you would specify. It isn't a way to create or retrieve a shared link. I see you were specifying a "url" parameter value of "https://api.dropboxapi.com/2/sharing/get_file_metadata", which is the Dropbox API endpoint, not a Dropbox shared link. You can find information about Dropbox shared links here.

     

    To create a shared link using the API, you would instead use /2/sharing/create_shared_link_with_settings. To list existing shared links, you would use /2/sharing/list_shared_links.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!