cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out 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: 

Can't use the content.dropboxapi

Can't use the content.dropboxapi

lonehero
Explorer | Level 4

I want to know what i did wrong in this code. Because it is giving error. I am new to this so plz help.

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

public class DropboxController
{
//Fetched from URL
String code;
String accesstoken;
public DropboxController()
{
code = ApexPages.currentPage().getParameters().get('code');
//Get the access token once we have code
if(code != '' && code != null)
{
AccessToken();
}
}

public PageReference DropAuth()
{
//Authenticating
PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=khvnmek12dw0wv9&redirect_uri...');
return pg;
}

public void AccessToken()
{
//Getting access token from dropbox
String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&code='+code+'&redirect_uri=http...';
HttpRequest req = new HttpRequest();
req.setEndpoint(tokenuri);
req.setMethod('POST');
req.setTimeout(60*1000);

Blob headerValue = Blob.valueOf('khvnmek12dw0wv9' + ':' + '<REDACTED>');
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();

JSONParser parser = JSON.createParser(resp);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){
String fieldName = parser.getText();
parser.nextToken();
if(fieldName == 'access_token') {
accesstoken = parser.getText();
}
}
}
system.debug('accessToken = '+accessToken );
System.debug(' You can parse the response to get the access token :: ' + resp);

string token = 'https://content.dropboxapi.com/2/files/download';
HttpRequest r = new HttpRequest();
r.setEndpoint(token);
r.setHeader('Authorization' , 'Bearer ' +accesstoken);
r.setHeader('Dropbox-API-Arg','{\"path\": \"/filepath\"}');
r.setMethod('GET');
r.setTimeout(60000);
Http h1 = new Http();
HttpResponse res1 = h1.send(r);
string resp1 = res1.getBody();
System.debug(' Information :- ' + resp1);
}
}

1 Accepted Solution

Accepted Solutions

Re: Can't use the content.dropboxapi

Greg-DB
Dropboxer

I see that you're trying to call the /2/files/download endpoint, and are getting a "path/not_found" error.

You can look up what each error for any particular endpoint means in the documentation for that endpoint. For example, for /2/files/download, the "path/not_found" error means: "There is nothing at the given path.". That is to say, there no file or folder at that particular path in the connected account.

In the code you shared, that's referring to the "/filepath" value you're supplying. I don't know if that's just an example or if that's the actual value you're sending, but you'll need to make sure you're supplying the right value. 

You can build these values manually, or you can get the paths for files by listing the contents of a folder using /2/files/list_folder[/continue].

The Content Access Guide and Namespace Guide may also serve as a useful reference here.

View solution in original post

2 Replies 2

Re: Can't use the content.dropboxapi

Greg-DB
Dropboxer

I see that you're trying to call the /2/files/download endpoint, and are getting a "path/not_found" error.

You can look up what each error for any particular endpoint means in the documentation for that endpoint. For example, for /2/files/download, the "path/not_found" error means: "There is nothing at the given path.". That is to say, there no file or folder at that particular path in the connected account.

In the code you shared, that's referring to the "/filepath" value you're supplying. I don't know if that's just an example or if that's the actual value you're sending, but you'll need to make sure you're supplying the right value. 

You can build these values manually, or you can get the paths for files by listing the contents of a folder using /2/files/list_folder[/continue].

The Content Access Guide and Namespace Guide may also serve as a useful reference here.

View solution in original post

Re: Can't use the content.dropboxapi

lonehero
Explorer | Level 4

Thanks my issue got solved.

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    lonehero Explorer | Level 4
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?