Fetch Email attachment from Purecloud API url (contentURI) and store as file in Salesforce

Hi,

If anyone can help me with this.

I use PureCloud API /api/v2/conversations/emails/{conversationId}/messages, to get email contentURI:
"attachments": [
{
"attachmentId": "c9b3c6f2-ddb2-4c90-a3.....",
"name": "xx.log",
"contentUri": "https://api.mypurecloud.com.au/api/v2/downloads/0d......",
"contentType": "application/octet-stream",
"contentLength": 189561,
"inlineImage": false
}

And I do httprequest in Salesforce to download this as a stream, as following:

        HTTP h = new HTTP();
        String authorizationHeader = 'Bearer  xxxxxxxxx';
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://api.mypurecloud.com.au/api/v2/downloads/0d0f.........');
        req.setMethod('GET');
       req.setHeader('Content-Type', 'application/octet-stream'); 
        req.setHeader('authorization',authorizationHeader);
        HttpResponse res = h.send(req);
        String body = res.getBody();
        system.debug('response: '+res.getStatus());
        if(body=='') return 'empty';
        else return body;

And it always endedup with result Response 303 - See other, although I have put bearer token properly (PureCloud - oauth grant implicit).

Thank you for help in advance.
Fransiska

That is correct. Please have your applicaiton follow the 303.

Thanks Tim for confirmation.

Will come back if there's further query.

Fransiska

hi @tim.smith ,

Just wondering, what is PureCloud API to get this link of this attachment ? (see yelow highlight)...

If i clicked this link, https://prod-apse2-recording-playback.s3.ap-southeast-2.amazonaws.com/MediaCache/37173e09-0828-4699-83ac-1905932f668a/......

And if i use this link in the Salesforce Apex /REST API, it working i able to transfer file to Salesforce, not getting error 303 anymore.

But is there any PureCloud API, that i can get result this link ?

Thank you
Fransiska

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.