You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

SauravGhosh14's avatar
SauravGhosh14
Explorer | Level 3
2 years ago

Getting a 500 error while sharing/create_shared_link_with_settings

I am trying to use Google Apps Script to create Shared links. I have been able to work most of the functinality I require, incl. running "sharing/list_shared_links".

 

My folder is a Team folder. Here are the important parts of "sharing/get_folder_metadata reads". At the moment I only have one file inside this folder.

"access_type": {
".tag": "editor"
},

"is_inside_team_folder": true,
"is_team_folder": false,

"policy": {
"member_policy": {
".tag": "anyone"
},
"resolved_member_policy": {
".tag": "anyone"
},
"acl_update_policy": {
".tag": "editors"
},
"shared_link_policy": {
".tag": "anyone"
},
"viewer_info_policy": {
".tag": "enabled"
}
}

 

If I try and use "create_shared_link_with_settings" I get a 500 error. At the same time, if I use the Dropbox Interface to create a View/Edit link to the file, I can use "list_shared_links" to get the link to that file. 

 
If I authorise another member of the team to pull "list_shared_links", they don't see the link I created using the interface. And they surely cannot use "create_shared_link_with_settings".
 
Am I missing something critical here.
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    A 500 error would indicate an issue on the server, so we'd need to look into that. I'll be happy to help with that, but I'll need some more information. Please reply with:

    • the steps to reproduce the issue with /sharing/create_shared_link_with_settings, including relevant code snippet(s), but don't include any access or refresh token(s)
    • several sample 'X-Dropbox-Request-Id' response header values for the failures with a 500 code
    • SauravGhosh14's avatar
      SauravGhosh14
      Explorer | Level 3

      Hi Greg-DB 

      Here is the code I am using 

       

      function generateLink_dropbox(id = "id:9TUWwcSqLjAAAAAAAAv4LA") {
      let token = "";
      const service = getService_();
      token = service.getAccessToken();
      const payload = {
      "path": id,
      "settings": {
      "access": "viewer",
      "audience": "public"
      }
      }
      const response = UrlFetchApp.fetch('https://api.dropboxAPI.com/2/sharing/create_shared_link_with_settings', {
      'method': 'POST',
      'payload': JSON.stringify(payload),
      'headers': {
      'Authorization': 'Bearer ' + token,
      'Content-Type': 'application/json',
      "Dropbox-API-Select-User": "dbmid:XXXX"
      },
      'muteHttpExceptions': true
      });
      const responseCode = parseInt(response.getResponseCode());
      const responseHeaders = response.getAllHeaders();
      Logger.log(responseCode);
      Logger.log(responseHeaders);
      Logger.log(response.getContentText());

       

      Here are a few X-Dropbox-Request-Id as requested

      45ea2e435c134d95896dfe501678c271

      7398c989168b4f9ab573604e11dfbf13

      66c98c4fe03e4c138f50bd9a9cb79854

      5883119e3efb4ef6957bec9969eea2e7

      78c28c5a2ffe4ae4a5682785c23496d3

       

      My apps script code works otherwise. I can get folder/file details. That's where I got the id of the file from.

       

      Now, if I manually create a link in the Dropbox UI for this particular file and re run this code, I obviously get a 409 error.

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

       

      In that case, when I manually create a link from the UI, I can get "sharing/list_shared_links" to work, no issues there.

       

      Funny thing though. Let's say I share this particular folder/file with my personal account. From my personal account, let's say I add it to my Dropbox (Join Folder). If I then run this code, "sharing/create_shared_link_with_settings" from my personal account, I can create links.

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        Thanks, that's helpful.

         

        For a file in the team space, you'll need to set the "Dropbox-API-Path-Root" accordingly in order to operate on it. The Team Files Guide has information on how to use that. Please update your code to set that.

         

        I'll also ask the team to fix up the error handling on the server to return a more useful error for this case.