Legacy Dev Forum Posts

 View Only

Sign Up

  • 1.  Download social media

    Posted 06-05-2025 18:23

    Vereb_Laszlo | 2022-08-30 11:59:38 UTC | #1

    When getting information about a social conversation, like Facebook using the https://api.{{environment}}/api/v2/conversations/messages/:conversationId API, the response contains participants[*].message[*].media[*].url field pointing to an image. I am trying to download it using ` HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofInputStream())` where request contains an "Authorization" header format("Basic %s", Base64.getEncoder().encodeToString(format("%s:%s", clientId, clientSecret).getBytes(StandardCharsets.UTF_8))). The returned response has status code of 303, the returned uri is the same as in request.

    Is there some description on how can I download them?


    Jerome.Saint-Marc | 2022-08-30 14:51:41 UTC | #2

    Hello,

    If I am not mistaken, the media url attribute (in Messages Conversation response) should have a format more or less like this: https://api-downloads.mypurecloud.ie/api/v2/downloads/xxxxxxxxx

    With these urls/endpoints (/api/v2/downloads), the download of a file is a two step process.

    1. Get a Download URL (Temporary) from the Media URL

    You will need to request a downloadUrl first (using the media url, and a Genesys Cloud Authorization Bearer token - this is NOT with Basic Auth). On success, by default, Genesys Cloud sends a 303 (Redirect) with Location Response Header containing the url to redirect to and to get the file from. You can prevent the 303 Redirect adding issueRedirect=false as a query parameter of your GET request.

    The url you get is to access the file on a Genesys Cloud repository (AWS S3). The url contains a temporary security/access token to access the file.

    GET https://api-downloads.mypurecloud.ie/api/v2/downloads/xxxxxxxxx, with Authorization: Bearer {YourGenesysCloudOAuthAccessToken} This will result in a 303 Redirect with Location Response Header containing the download url

    or GET https://api-downloads.mypurecloud.ie/api/v2/downloads/xxxxxxxxx?issueRedirect=false, with Authorization: Bearer {YourGenesysCloudOAuthAccessToken} This will result in a 200 OK with the response body (JSON) containing a url attribute (download url).

    1. Download the file

    Download the file from the download url: GET {the download url} YOU MUST NOT SET/SEND AN AUTHORIZATION HEADER ON THIS HTTP REQUEST. The security token (temporary) is sent as a query parameter (defined in the download url).

    Regards,


    system | 2022-09-30 14:51:47 UTC | #3

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


    This post was migrated from the old Developer Forum.

    ref: 16072