You need to sign in to do that
Don't have an account?
Adam Cimino 3
Apex Callouts retrieve audio content
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) {
}
}
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) {
}
}
Shashank (Salesforce Developers)
Looks like your question has been answered here. Posting for others' reference: http://salesforce.stackexchange.com/questions/81859/apex-callouts-retrieve-audio-content