0

I am making a callout to a 3rd party to retrieve an mp3 file The endpoint is a HTTP GET (https://api.ubity.com/recording?key=HV5nPTLk98UPeTLxqwA8&callid=ABC12345) The response is the actual MP3 file, with a Content-Type: audio/mpeg header.

I am having trouble retrieving the audio file from the response body. The body is empty. Using my browser and rest clients I do see that the endpoint works and the mp3 file is returned When I perform the callout it returns successfully with STATUS:OK and STATUS_CODE:200 so the actual call works I assume that either I am trying to access the file from the http response incorrectly or salesforce is dropping the mp3 file I have tried other HTTP GET services from the same provider and they do in fact return content in the body. It seems to be only in the case for the mp3 file Here is my code.

@future (callout=true)
public  static void getCallLogRecording(Id callLogId, String callid){
    try {
        CallLogSettings__c callLogSettings = CallLogSettings__c.getOrgDefaults();
        HttpRequest req = new HttpRequest(); 
        req.setMethod('GET');
        req.setEndpoint(callLogSettings.record_end_point__c+'?key=' + callLogSettings.key__c+'&callid='+ callid);
        req.setHeader('Connection','keep-alive');
        req.setHeader('Host','api.ubity.com');
        req.setHeader('content-type', 'audio/mpeg');
        Http http = new Http();
        HTTPResponse res = http.send(req);  
        System.debug(res.toString());
        System.debug(res.getBody());
        System.debug('STATUS:'+res.getStatus());
        System.debug('STATUS_CODE:'+res.getStatusCode());
    } catch(Exception e) {

    }       
}
0
    HTTPResponse res = http.send(req);  
    System.debug(res.toString());
    System.debug('CHECK BLOB...'+res.getBodyAsBlob());//Debug this as well 
    System.debug('CHECK BLOB...'+res.getBodyDocument());//Debug this
    System.debug('STATUS:'+res.getStatus());
    System.debug('STATUS_CODE:'+res.getStatusCode());

I would see blob data as well as body Document in case this helps us digging further

  • 1
    the res.getBodyDocument() holds the content thank you – medaxis Jul 2 '15 at 18:04
  • 1
    sorry it the getBodyAsBlob() that works – medaxis Jul 2 '15 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.