PureCloudPlatformClientV2.OutboundApi() how to extract data

Hi,

I am trying to export the contact list data for a specific Contact list ID, but I am trying to figure out why the data from the URI I am reading is HTML?

The below python script seems to work fine.
When I manually click on the api_response.uri link it does download the required data in .CSV file
When i try to read the csv file from the URI within the python script, it returns a HTML file.

Below is the script I am using.
Any thoughts on how I can load this file in python?

import os
from PureCloudPlatformClientV2.rest import ApiException
from pprint import pprint
import datetime
import logging
import requests
import json
import certifi
import os
from datetime import date
import time
import csv
import inspect
import pandas as pd

region = PureCloudPlatformClientV2.PureCloudRegionHosts.eu_west_1
PureCloudPlatformClientV2.configuration.host = region.get_api_host()

GENESYS_CLOUD_CLIENT_ID = 'x'
GENESYS_CLOUD_CLIENT_SECRET = 'x'

apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(GENESYS_CLOUD_CLIENT_ID,GENESYS_CLOUD_CLIENT_SECRET)
#print(apiclient.access_token)
PureCloudPlatformClientV2.configuration.access_token = apiclient.access_token

create an instance of the API class

api_instance = PureCloudPlatformClientV2.OutboundApi()
contact_list_id = 'x' # str | Contactlist ID

try:
# Get a basic ContactList information object
api_response = api_instance.get_outbound_contactlist_export(contact_list_id)
pprint(api_response)
export_uri = api_response.uri
pprint(export_uri)
#dataset = pd.read_csv(export_uri,sep=",")
#display(dataset)

except ApiException as e:
print("Exception when calling GetOutboundContactlistsDivisionviewRequest->get_outbound_contactlists_divisionview: %s\n" % e)

Hello

When you invoke get_outbound_contactlist_export(), you receive the download uri. At the end of this URI is the download ID. You can then use this download ID in a call to GET /api/v2/downloads/{downloadId}. (You will see an example of this operation using the python sdk in this link.). This will return the download URI that will download the csv data to your machine on a basic GET request.

Hope this helps,
Charlie

Hi Charlie,

Thanks for pointing me in the right direction.
I think the link you sent brings you to the old documentation but I was able to get a little further by following the example here: https://developer.genesys.cloud/devapps/sdk/docexplorer/purecloudpython/DownloadsApi

api_instance_download = PureCloudPlatformClientV2.DownloadsApi()
download_id = 'x' # str | Download ID
#content_disposition = 'content_disposition_example' # str | (optional)
#issue_redirect = True # bool | (optional) (default to True)
#redirect_to_auth = True # bool | (optional) (default to True)

try:
# Issues a redirect to a signed secure download URL for specified download
api_response_download = api_instance_download.get_download(download_id)
pprint(api_response_download)
pprint(api_response_download.url)
except ApiException as e:
print("Exception when calling DownloadsApi->get_download: %s\n" % e)

When i print the api_response_download.url from above script it retrurns "None"

I am wondering why that might be as the download_id I am passing in seems to be correct.

Thanks,
Mihail

Hi Mihail

The example you provided above worked for me after I set issue_redirect and redirect_to_auth to False.

Hope this helps,
Charlie

Hi Charlie,

yes, setting the 2 parameters to False worked.

Thanks for your help.

Regards,
Mihail

1 Like

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