Mentioning @Jerome.Saint-Marc just in case he can also help, because I'm totally frustrated with this, cannot make it work. Thanks a lot both in advance.
I've tried to follow what Jerome describes in the other post. This is my javascript code to try to get the csv resulting from the contact list export:
let selectedContactListId;
let csvData;
function handleContactListSelection(platformClient, contactListId, clientId) {
selectedContactListId = contactListId;
initiateContactListExport(platformClient, contactListId, clientId);
}
function initiateContactListExport(platformClient, contactListId, clientId) {
const apiInstance = new platformClient.OutboundApi();
apiInstance.postOutboundContactlistExport(contactListId)
.then(response => {
console.log('Export initiated:', response);
setTimeout(() => {
getDownloadUrl(platformClient, contactListId, clientId);
}, 2000);
})
.catch(error => console.error('Error initiating contact list export:', error));
}
function getDownloadUrl(platformClient, contactListId, clientId, tries = 0) {
const apiInstance = new platformClient.OutboundApi();
apiInstance.getOutboundContactlistExport(contactListId)
.then((data) => {
console.log(`getOutboundContactlistExport success! data: ${JSON.stringify(data, null, 2)}`);
console.log('Download URL retrieved:', data.uri);
const modifiedUrl = data.uri + '?issueRedirect=false';
console.log('Modified URL:', modifiedUrl);
downloadExportedCsv(modifiedUrl);
})
.catch((err) => {
console.log("failure getting export URL");
console.error(err);
});
}
async function downloadExportedCsv(uri) {
try {
const response = await fetch(uri);
if (!response.ok) {
throw new Error(`Error when downloading CSV: ${response.statusText}`);
}
const csvData = await response.text();
showContactListRecords(csvData);
} catch (error) {
console.error('Error:', error);
}
}
Here the sequence of API calls I see in browser debugger, network tab:
- Request URL:
api/v2/outbound/contactlists/cd95e9e............/export
- Request Method:
POST
- Status Code:
200 OK
- Request URL:
api/v2/outbound/contactlists/cd95e9e6-................/export
- Request Method:
GET
- Status Code:
200 OK
- Request URL:
api/v2/downloads/96894..........?issueRedirect=false
- Request Method:
GET
- Status Code:
303 See Other
Request URL: xxxxxxxx/authorize?response_type=code&redirect_uri=https%3A%2F%2Fapi.mypurecloud.de%2Fapi%2Fv2%2Fdownloads%2Fcallback&state=968944a.......&client_id=181dfaa.....
Request Method: GET
Status Code: 302
Error on console tab:
Access to fetch at '......./authorize?response_type=code&redirect_uri=https%3A%2F%2Fapi.mypurecloud.de%2Fapi%2Fv2%2Fdownloads%2Fcallback&state=9689......&client_id=181df.......' (redirected from 'api/v2/downloads/96894......?issueRedirect=false') from origin 'xxxxxxxxx.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I have tried many variants, but it always end in CORS error or AWS error ( <?xml version="1.0" encoding="UTF-8"?> InvalidArgument
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified Authorization ...). Those variants include also not appending "?issueRedirect=false" in the URL, and also setting the download flag to false, and then another different try with that flag set to true:
let opts = {
"download": "false"
};
apiInstance.getOutboundContactlistExport(contactListId, opts)
Nothing worked...