Getting 403 error with Salesforce and Sharefile API v2

  • 1
  • Question
  • Updated 7 months ago

I have an application in Salesforce that uses the ShareFile v3 API to make files stored in ShareFile available to our Salesforce Community users. 

 

Everything was working fine until about three weeks ago, but now users can see the folders and files displayed via the API, but when they click on a file to open it, they get the following error message:  “You do not have permission to view this directory or page” (with a 403 status code). 

 

The application code has not been modified in the past year.

 

I tested one of our affected users in Postman, and I am able to access files correctly, so it’s not an issue with user permissions.

 

 

The following code yields the 403 error:

 

 public static String getLink(Citrix_ShareFile_Credentials__c citrixShareFileCredentials, String id) {
    return getLink(citrixShareFileCredentials, true, id);
  }
  
  public static String getLink(Citrix_ShareFile_Credentials__c citrixShareFileCredentials, Boolean refreshTokens, String id) {
    Citrix_ShareFile_Settings__c citrixShareFileSettings = Citrix_ShareFile_Settings__c.getInstance(UserInfo.getOrganizationId());
    
    String url = citrixShareFileSettings.API_Host__c + '/sf/v3/Items(' + id + ')/Download';

    HttpRequest httpRequest = new HttpRequest();
    httpRequest.setTimeout(60 * 1000);
    httpRequest.setEndpoint(url);
    httpRequest.setMethod('GET');
    httpRequest.setHeader('Authorization', 'Bearer ' + citrixShareFileCredentials.Access_Token__c);
    
    HttpResponse httpResponse = (new Http()).send(httpRequest);

 

 

 

The following code IS working properly:

 

 public static Item getFolder(Citrix_ShareFile_Credentials__c citrixShareFileCredentials, Boolean refreshTokens, String id) {
    Citrix_ShareFile_Settings__c citrixShareFileSettings = Citrix_ShareFile_Settings__c.getInstance(UserInfo.getOrganizationId());
    
    String url = citrixShareFileSettings.API_Host__c + '/sf/v3/Items(' + id + ')?$expand=Children';
    
    HttpRequest httpRequest = new HttpRequest();
    httpRequest.setTimeout(60 * 1000);
    httpRequest.setEndpoint(url);
    httpRequest.setMethod('GET');
    httpRequest.setHeader('Authorization', 'Bearer ' + citrixShareFileCredentials.Access_Token__c);
    
    HttpResponse httpResponse = (new Http()).send(httpRequest);

 

 

 

 
Photo of djackie m

djackie m

  • 1 Post
  • 0 Reply Likes

Posted 7 months ago

  • 1

Be the first to post a reply!