Convert PDF documents with Salesforce using Aspose Cloud REST API returns 403 status

Hi,

We use the Aspose Cloud to convert pdfs but today it stopped working and we are keep getting a 403 status returned when performing the conversion.

Please note, this issue has been ongoing for at least today, UK time. It last worked fine on Friday.

Hope you revert back soon.

This message was posted using Email2Forum by Babar Raza.

Hi,

We have implemented auto-scaling architecture which automatically starts new servers in case there is any issue with an existing server or workload is too much for existing servers to handle.

Our cloud service was migrated to this new architecture on this weekend. There are chances some of your input files are not migrated. Can you please re-upload your files and try again? If the problem persists, please share the following information:

  • Your App SID and App Key
  • Your email which is registered with your account
  • Your code
  • A sample document (if possible)

You can send this information to me at muhammad.ijaz@aspose.com

Best Regards,

We are getting a 403 error for any request, even for files we have just uploaded. Is there a problem with our account?

Hi,

We are looking into this matter and will get back to you soon. We are sorry for this inconvenience.

Hi Paul,

Are you getting this error with HTTPS only or HTTP also?

Best Regards,

HTTPS only, HTTP works but we’d rather not send potentially sensitive data unsecured.

Hi Paul,

I am working on Sign method for Salesfore and will share it with you soon. After that update, you will be able to use HTTPS.

Sorry for the inconvenience.

Best Regards,

Any more news on this problem? Why has it stopped working?

Hi Paul,

A couple of changes are required in Sign method of your Salesforce code. I will send you updated method tomorrow morning. At the moment, updated Sign method is available for .NET and PHP only. I can send you .NET Sign method and some description of the required changes if you want to update Sign method by yourself.

Best Regards,

Muhammad,

When can you update me on the Signing method?

I’ve used the one from the documentation and it doesn’t work.

Even a PHP version would help me understand the differences we need to make.

This is causing us a lot of problems, as this has been out of use for us since the 9th of December.

Regards,
Paul

Hi Paul,

Sorry for getting back to you late. Please use the following Sign method in Salesforce. It should work fine with HTTPS.

public static String Sign(String data ) {

String HMAC_SHA1 = 'HmacSHA1';

try {

data = data .replace(' ', '%20');
URL url = new URL(data );
String path = url.getPath();
path = path.replace(' ', '%20');
// Remove final slash here as it can be added automatically.
path = path.removeEnd('/');
String filePart = url.getPath() + (url.getQuery() == null ? '?'+ 'appSID=' + AsposeCloudApp.AppSID : '?' + url.getQuery()+ '&appSID=' + AsposeCloudApp.AppSID);
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), filePart);
// compute the hmac on input data bytes
Blob mac = Crypto.generateMac('hmacSHA1', Blob.valueOf(filePart), EncodingUtil.base64Decode(AsposeCloudApp.AppKey));
String base64 = EncodingUtil.base64Encode(mac);
system .debug('base64: ' + base64);
// Remove invalid symbols.
String result = base64.replace('+', '-').replace('/', '_');
system .debug('signature: ' + result);
String encodedUrl = url.toExternalForm() + '&signature=' + result;
system .debug('full URL: ' + encodedUrl);
return encodedUrl;

} catch (Exception ex) {

system .debug(ex.getStackTraceString());
return null ;

}

}

Please try this at your end and let us know if it works for you as well.

Best Regards,

Sadly this doesn’t work, we get the same error as before.

System.HttpResponse[Status=Forbidden, StatusCode=403]

Hi Paul,

I just updated the code in my previous post. Please do not forget to use updated Sign method. Following line is the updated one.

String result = base64.replace('+', '-').replace('/', '_');

Best Regards,

The service has now started working properly, but I haven’t changed any code.

Can you tell me what has happened with the platform as it’s now working perfectly, and we haven’t made any production changes?

Hi Paul,

HTTP was working normally but for HTTPS requests, verification of signatures process was not working for some specific accounts. Most of the accounts were working with HTTPS but surprisingly some accounts were not working.

My previous code was just a workaround. Now we have fixed the issue with all such accounts and you can continue using your existing code.

Best Regards,

@support_nwright

We want to share an update. Now, we have released Aspose.PDF Cloud API Version 3.0. It has a more simplified API structure and better memory management than the older version. It usesJSON Web Token(JWT) for a request authorization and provides Storage API methods for cloud storage operations. Please find the sample Apex code to get the JWT access token and you can pass it in your API request instead of using the old sign method. Please feel free to contact us for any further assistance.

//Function to get the JSON WEB Token

public static string GetJWT(String client_id, String client_secret){
        String grant_type = 'client_credentials';
    
        HttpRequest request = new HttpRequest();
        
        request.setEndpoint('https://api.aspose.cloud/connect/token');
        request.setMethod('GET');                
        request.setHeader('Content-Type', 'application/x-www-form-urlencoded');              
        request.setHeader('Accept', 'application/json');
        
        String body = 'grant_type=' + grant_type + '&client_id=' + client_id + '&client_secret='+ client_secret ;
        request.setBody(body);
        
        Http http = new Http();
        HttpResponse res = http.send(request);
        String jsonInput = res.getBody();
        Map<String, Object> a =(Map<String, Object>)JSON.deserializeUntyped(jsonInput);
        system.debug('JWT Token is: '+a.get('access_token'));
        
        return a.get('access_token').ToString();
    }