Szlaski_Daniel | 2018-04-25 16:16:15 UTC | #1
Hi,
I've tried go through steps listed below: http://developer.mypurecloud.com/forum/t/read-contactlist-as-stream/1220
as well as just direct download. Each time, I'm able to get download uri like (https://api.mypurecloud.ie/api/v2/downloads/cdd148ee) When I copy&paste it to browser - I get proper csv file.
But when download it from NodeJS (including Authorization Barer Token) - I only get strange webPage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PureCloud</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="assets/images/ico/genesys-logo-red-180.png">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="assets/images/ico/genesys-logo-red-152.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/images/ico/genesys-logo-red-144.png">
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="assets/images/ico/genesys-logo-red-120.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/images/ico/genesys-logo-red-114.png">
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="assets/images/ico/genesys-logo-red-76.png">
<link rel="apple-touch-icon-precomposed" href="assets/images/ico/genesys-logo-red-57.png">
<link rel="shortcut icon" href="assets/images/ico/genesys-logo-red.ico">
<meta name="csrf" content="KnA2VkEW7ScB2Eq_Xw0uwpSEQkLLwwSL9y_x_sCJxCs">
<meta name="requestId" content="aY4T-sqQWsgEaU_lJ5KAL0Lv-TEvk4PUW_KmvOqeQWg">
<meta name="web-auth-service/config/environment" content="%7B%22modulePrefix%22%3A%22web-auth-service%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22/%22%2C%22locationType%22%3A%22hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%7D%7D%2C%22APP%22%3A%7B%22name%22%3A%22web-auth-service%22%2C%22version%22%3A%222.17.0+012c7c11%22%7D%2C%22bootstrap%22%3A%7B%22attemptCountKey%22%3A%22pcAuth-reloadAttempts%22%2C%22maxAttempts%22%3A3%7D%2C%22localeCookie%22%3A%7B%22name%22%3A%22pcAuth-userPrefLangTag%22%2C%22legacyName%22%3A%22pcAuth-userPrefLocale%22%2C%22expirationDays%22%3A90%7D%2C%22lockOutMinutes%22%3A5%2C%22autoDirect%22%3A%7B%22on%22%3Afalse%2C%22url%22%3Anull%2C%22protocol%22%3A%22https%22%2C%22hostPrefix%22%3A%22apps%22%2C%22pathname%22%3A%22/architect/%22%7D%2C%22restoreOrgNameCookie%22%3A%22pcAuth-prevOrgName%22%2C%22restoreOrgNameCookieExpirationDays%22%3A90%2C%22helpSystem%22%3A%7B%22signUpUrl%22%3A%22https%3A//apps.mypurecloud.com/signup/%23/account%22%2C%22linkBase%22%3A%22http%3A//help.mypurecloud.com%22%2C%22i18nLinkBase%22%3A%22http%3A//help.mypurecloud.com/redirect%22%7D%2C%22apps%22%3A%7B%22baseUrl%22%3Anull%2C%22baseProtocol%22%3A%22https%22%2C%22baseHostPrefix%22%3A%22apps%22%2C%22pathnames%22%3A%7B%22collaborate%22%3A%22/directory%22%2C%22communicate%22%3A%22/directory/%23/search%22%2C%22engage%22%3A%22/contact-center%22%2C%22architect%22%3A%22/architect%22%2C%22admin%22%3A%22/admin%22%2C%22collaborateBundle%22%3A%22/directory%22%7D%7D%2C%22exportApplicationGlobal%22%3Afalse%7D" />
<script src="/assets/intl/intl.min-50b782c1f6d9a43411a8603a5a3d9234.js" integrity="sha256-syHhPttPabh44mVQM5ApckIpJnjHrfamoBiE/tmh+Kc= sha512-yyMXGr0VEGFF3Gkso4zm7QyS0OZk0cg2EloVSyABaD0pcKScoI+FKJQibRTXhVr2JubnulNNCZxTw59cGSqENg==" ></script>
<script src="/assets/intl/locales/en-us-a53ee708f8f05d570a3095cbc9cec948.js" integrity="sha256-2p6FY8PWvyhgctwbeDZc+u6w+8bsg9cKdjmGq3aWWD8= sha512-ypUJzoM4T4mLVfE2txsFxmB4nz8t05kTWUog+wk22vcNpv0qBDDosGkrJf1u1HIvIsKH4bFsOEFlU3imKeOFQA==" ></script>
<link href="//fonts.googleapis.com/css?family=Lato:400" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css" integrity="sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU= sha512-z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg==" >
<link rel="stylesheet" href="/assets/web-auth-service-0a3aa9dfcd5975fb161fed2a172b8292.css" integrity="sha256-XGLTZCM5wANs/DpakoLAfS+IqeR3hym/vWvckLFZLFk= sha512-Pi+7iTpPwTtVsxuP8zRCZIct7bICnloChDkpqNLy7kPyLZSWG83eLRpT3SyrIBtG2DyvUjh/hsvylDfvhmoq+g==" >
</head>
<body>
<script src="/assets/vendor-726296b190a9ed5edaac0cb5571c0a28.js" integrity="sha256-KI7xOkcaoPShP/fRLYjt1F8f646ya+dbxTa2amgZ7ZM= sha512-/2adzsYPXzXadxdymRDvXtAYWaOMzNCXPBCjeT31Z/4y+RZOxo4nLtVQpr2me5cL8yYiFd7sulomw9Bs5qIDYg==" ></script>
<script src="/assets/web-auth-service-3247ebfaf664a72315c37bab5066f75a.js" integrity="sha256-immcSojp9QGM4TDPqPz+FD2l+0mWu6EgU+1Lwi5sTTY= sha512-kogs+wsW1eFgQUIlMrunrdhvPJC3zTsPALNdPLL7vHjUEOPHqP1OTYZzOGltA+YKdpPxAChEHVgdiQzlki+TuA==" ></script>
</body>
</html>
tim.smith | 2018-04-25 16:52:47 UTC | #2
This code works fine for me. Are you doing something differently?
const platformClient = require('purecloud-platform-client-v2');
const request = require('request-promise');
const client = platformClient.ApiClient.instance;
const outboundApi = new platformClient.OutboundApi();
client.loginClientCredentialsGrant(process.env.PURECLOUD_CLIENT_ID, process.env.PURECLOUD_CLIENT_SECRET)
.then(() => {
// Initiate export
return outboundApi.postOutboundContactlistExport('f19465cf-5bc6-4871-b59f-5307575ddddf');
})
.then((res) => {
// Get download URL
return outboundApi.getOutboundContactlistExport('f19465cf-5bc6-4871-b59f-5307575ddddf', { download: false });
})
.then((res) => {
// Download file
return request({
uri: res.uri,
headers: {
'authorization': `bearer ${client.authData.accessToken}`
}
});
})
.then((res) => {
// Show downloaded file in console
console.log(res);
})
.catch(function(err) {
// Handle failure response
console.log(err);
});
BTW, that HTML you're getting is the login UI. You'll get that if your request didn't contain proper authentication.
Szlaski_Daniel | 2018-04-26 08:13:03 UTC | #3
BTW, that HTML you're getting is the login UI. You'll get that if your request didn't contain proper authentication.
Thank you for point this out. This was the issue, typo for bearer keyword. After getOutboundContactlistExport I needed to use ?issueRedirect=false to get Full AWS Url, but in the end, final download request works now fine.
Thx for help.
system | 2018-05-27 08:13:10 UTC | #4
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: 2784