Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
barryplum
4 months agoExplorer | Level 3
Dropbox App created with one account, but seems to be identifying as a different account
I've created an app with a dedicated account that our administrator set up for me. The app works great. I've set up Salesforce to connect to the app using an Auth. Provider and Named Credentials. ...
barryplum
4 months agoExplorer | Level 3
Here is the response to get_current_account for the user that the app is built under:
{ "account_id": "dbid:AAA...", "name": { "given_name": "iSpot", "surname": "TV", "familiar_name": "iSpot", "display_name": "iSpot TV", "abbreviated_name": "IT" }, "email": "XXX", "email_verified": true, "disabled": false, "country": "US", "locale": "en", "referral_link": "https://www.dropbox.com/referrals/AACYm_TyrF5o2xgAwv-HbCNzPr3B0h3ua-g?src=app9-806211", "team": { "id": "dbtid:AAA...", "name": "IspotTV", "sharing_policies": { "shared_folder_member_policy": { ".tag": "anyone" }, "shared_folder_join_policy": { ".tag": "from_anyone" }, "shared_link_create_policy": { ".tag": "default_public" }, "group_creation_policy": { ".tag": "admins_and_members" }, "shared_folder_link_restriction_policy": { ".tag": "anyone" }, "enforce_link_password_policy": { ".tag": "optional" }, "default_link_expiration_days_policy": { ".tag": "none" }, "shared_link_default_permissions_policy": { ".tag": "default" } }, "office_addin_policy": { ".tag": "enabled" }, "top_level_content_policy": { ".tag": "admin_only" } }, "team_member_id": "dbmid:AAA...", "is_paired": false, "account_type": { ".tag": "business" }, "root_info": { ".tag": "user", "root_namespace_id": "1276...", "home_namespace_id": "1276...", "home_path": "/iSpot TV" } }
Here is the class that I'm using to connect to the app:
public with sharing class DropboxIntegration { // Constants for Dropbox API endpoints private static final String API_CREATE_FOLDER = 'callout:Dropbox_prod/sharing/share_folder'; private static final String API_CREATE_SHARED_LINK = 'callout:Dropbox_prod/sharing/create_shared_link_with_settings'; private static final String API_CREATE_FILE_REQUEST = 'callout:Dropbox_prod/file_requests/create'; // Inner class for invocable method inputs public class DropboxActionInput { @InvocableVariable(label='Base Folder Path' description='The base path for the new Dropbox folder (e.g., /Apps/Salesforce).') public String baseFolderPath; @InvocableVariable(label='Folder Name' description='The name of the new folder to be created in Dropbox.') public String folderName; @InvocableVariable(label='Create Folder' description='Set to true to create a new Dropbox folder.') public Boolean createFolder; @InvocableVariable(label='Create File Request' description='Set to true to create a Dropbox file request link.') public Boolean createFileRequest; } // Inner class for invocable method outputs public class DropboxActionResult { @InvocableVariable(label='Operation Result' description='The combined result message of the Dropbox operations.') public String resultMessage; } @InvocableMethod(label='Automate Dropbox Folder & File Request' description='Creates a Dropbox folder and/or a file request link.') public static List<DropboxActionResult> automateDropbox(List<DropboxActionInput> inputs) { List<DropboxActionResult> results = new List<DropboxActionResult>(); for (DropboxActionInput input : inputs) { String folderName = input.folderName; String baseFolder = String.isNotBlank(input.baseFolderPath) ? input.baseFolderPath : 'Pre Test Creatives'; Boolean doCreateFolder = input.createFolder != null && input.createFolder; Boolean doCreateFileRequest = input.createFileRequest != null && input.createFileRequest; // Clean the folder name to remove characters that might be invalid in a path String sanitizedFolderName = folderName.replaceAll('[^a-zA-Z0-9_ -]', ''); String folderPath = '/' + baseFolder + '/' + sanitizedFolderName; String folderCreationResult = ''; boolean folderOperationSuccess = false; // --- Create Folder --- if (doCreateFolder) { String requestBody = '{"path": "' + folderPath + '"}'; HttpResponse res = makeDropboxApiCall(API_CREATE_FOLDER, 'POST', requestBody); if (res.getStatusCode() == 200) { folderCreationResult = 'Success: Folder "' + folderPath + '" created.'; folderOperationSuccess = true; } else { folderCreationResult = 'Error creating folder: ' + res.getBody(); } } // --- Create Shared Link --- String sharedLinkResult = ''; if (folderOperationSuccess) { String requestBody = '{"path": "' + folderPath + '"}'; HttpResponse res = makeDropboxApiCall(API_CREATE_SHARED_LINK, 'POST', requestBody); if (res.getStatusCode() == 200) { Map<String, Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(res.getBody()); String shareUrl = (String) responseMap.get('url'); sharedLinkResult = 'Success: Link to share: <sofs>' + shareUrl + '<eofs>'; } else { sharedLinkResult = 'Error creating share: ' + res.getBody(); } } // --- Create File Request --- String fileRequestResult = ''; if (doCreateFileRequest && (folderOperationSuccess || !doCreateFolder)) { String title = 'Files for ' + folderName; String requestBody = '{"destination": "' + folderPath + '","title": "' + title + '"}'; HttpResponse res = makeDropboxApiCall(API_CREATE_FILE_REQUEST, 'POST', requestBody); if (res.getStatusCode() == 200) { Map<String, Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(res.getBody()); String url = (String) responseMap.get('url'); fileRequestResult = 'Success: File request link created: <sofr>' + url + '<eofr>'; } else { fileRequestResult = 'Error creating file request: ' + res.getBody(); } } else if (doCreateFileRequest && !folderOperationSuccess) { fileRequestResult = 'Skipped file request due to folder creation error.'; } // --- Consolidate Results --- List<String> finalMessages = new List<String>(); if (String.isNotBlank(folderCreationResult)) finalMessages.add(folderCreationResult); if (String.isNotBlank(sharedLinkResult)) finalMessages.add(sharedLinkResult); if (String.isNotBlank(fileRequestResult)) finalMessages.add(fileRequestResult); DropboxActionResult actionResult = new DropboxActionResult(); actionResult.resultMessage = String.join(finalMessages, '\n'); results.add(actionResult); } return results; } /** * @description Helper method to make a callout to the Dropbox API. * @param endpoint The API endpoint to call. * @param method The HTTP method (e.g., 'POST'). * @param body The request body. * @return The HttpResponse from the callout. */ private static HttpResponse makeDropboxApiCall(String endpoint, String method, String body) { HttpRequest req = new HttpRequest(); req.setEndpoint(endpoint); req.setMethod(method); req.setHeader('Content-Type', 'application/json'); req.setHeader('Dropbox-API-Path-Root','{".tag": "namespace_id", "namespace_id": "12762239491"}'); req.setBody(body); Http http = new Http(); try { return http.send(req); } catch (Exception e) { HttpResponse errorResponse = new HttpResponse(); errorResponse.setStatusCode(500); errorResponse.setBody('Exception during callout: ' + e.getMessage()); return errorResponse; } } }
I tried updating the header to use the namespace_id and I get the no_permission error.
Here is the full response I was getting back when I was trying to use root in the header:
Error creating folder: {"error":{".tag":"invalid_root","invalid_root":{".tag":"team","home_namespace_id":"1229...","home_path":"/Barry ...","root_namespace_id":"1229..."}},"error_summary":"invalid_root/"}
Skipped file request due to folder creation error.
Which seems to indicate that it thinks I'm authenticated as Barry ..., not iSpot TV. But I don't have any credentials that are connected to my user account.
- DB-Des4 months ago
Dropbox Community Moderator
Based on the error, it does appear as though the access token being used is for your user (Barry) . We'd recommend re-authenticating, while logged in as the iSpot TV user, and using the resulting access token.
- barryplum4 months agoExplorer | Level 3
OK, so I figured out the user issue. When I authenticated my named credentials, I must not have realized that I was logged into dropbox as my user account instead of system account. It is now creating folders under the system account.
It's still not using the team folder as the parent for the folders that I'm creating. I've tried specifying the path, but it just creates a folder of the same name under the root of the system account.
I think we're 99% there, but even though I've created a folder share, the share can see the folder, but not the contents of the folder.
The end goal of the project is to create a folder based on a record in salesforce. Then, create a file request link so that a customer can upload the file into that folder. Finally provide a link to an internal user to be able to go to that folder and download whatever the customer uploads.
- DB-Des4 months ago
Dropbox Community Moderator
It's still not using the team folder as the parent for the folders that I'm creating. I've tried specifying the path, but it just creates a folder of the same name under the root of the system account.
A couple of things to keep in mind:
- If you are trying to create a team folder in the team space, you will need to use the /2/team/team_folder/create endpoint.
- If you are trying to create a folder inside an existing team folder (in the team space), you can use /2/files/create_folder_v2, but you will need to include both the 'Dropbox-API-Path-Root' (with the root namespace ID) and 'Dropbox-API-Select-User' headers.
I think we're 99% there, but even though I've created a folder share, the share can see the folder, but not the contents of the folder.
You can update the access level for folder members, by sending a request to the /2/sharing/update_folder_member endpoint.
About 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!