andygunther | 2016-09-23 17:45:55 UTC | #1
I am trying to use the Aggregate Query example (https://developer.mypurecloud.com/api/tutorials/analytics-conversation-aggregate-query/#javascript) and when I run the example, I get an error in the javascript that "purecloud" is not defined:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/1f320bcfd73be380359c99c7e6917164bed31bbc.png" width="661" height="116">
Which is odd, because it is here in the javascript, and intellisense seems to understand it's members:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/4872d82ba8f55e55e5900dec2e36904a83f4147b.png" width="690" height="164">
Probably something very stupid on my part - I am not very strong with javascript.
Any thoughts on what I might be missing?
KevinGlinski | 2016-09-23 17:52:54 UTC | #2
is purecloud-api.min.js successfully loading for you?
andygunther | 2016-09-23 17:55:09 UTC | #3
I pulled it out of GitHub and put it in the root with the html file. And, the reference is local:
script src='purecloud-api-min.js'
So, I assume so, but I'm not sure how to tell for sure.
KevinGlinski | 2016-09-23 18:03:59 UTC | #4
your network tab will tell you, the console should also say if it didn't loaded, it does in chrome, not sure about firefox
andygunther | 2016-09-23 18:08:56 UTC | #5
Yup - 404 Not Found... Huh. I'll have to figure that out I guess :slight_smile: Thanks!
andygunther | 2016-09-23 18:48:14 UTC | #6
OK, fixed that, which was bizarre... Now I'm getting the same Not defined error on RoutnigApi, here:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/38dc4aa3edb28c2afdaeec1bcb8c1314096831f9.png" width="478" height="43">
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/c1cf46310e6719e61ad6842b5b56da814139c50f.png" width="664" height="87">
KevinGlinski | 2016-09-23 18:54:20 UTC | #7
that should be purecloud.platform.RoutingApi, we changed it a while back to put everything in the purecloud.platform namespace and missed those updates in the tutorial.
andygunther | 2016-09-23 18:57:17 UTC | #8
Aha - ok good. Just about there then...
Authentication is failing. I have the correct Client Id referenced, I think. At least, that's the same Client Id I use when requesting an Authorization Token in a C# IVR service I'm using.
So, this is probably me not understanding how to use the API properly. But, I get this response now when the page loads:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/a8322c21a843ef2b26430d513b4022ba15c57b37.jpg" width="570" height="410">
KevinGlinski | 2016-09-23 18:59:02 UTC | #9
your oauth client needs to be configured specific for your application, so in this case will need to be implicit grant and a localhost redirect uri
andygunther | 2016-09-23 19:43:38 UTC | #10
So close :slight_smile:
I'm now getting a Bad Request response. Something malformed in the query maybe? I kept all of the defaults in the example, except changed the queue name to one of our real queues.
Here are the request details:
Host: api.mypurecloud.com User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0 Accept: application/json Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate, br Content-Type: application/json Authorization: bearer ******************** Referer: http://localhost:55979/ Content-Length: 265 Origin: http://localhost:55979 Connection: keep-alive
{"interval":"2016-09-02T19:40:03.936Z/2016-09-23T19:40:03.936Z","groupBy":["queueId"],"metrics":["nOffered","tAnswered","tTalk"],"filter":{"type":"and","clauses":[{"type":"or","predicates":[{"dimension":"queueId","value":"5aa5748e-bee8-4b48-bcd1-bfb3b9f6890f"}]}]}}
andygunther | 2016-09-23 19:47:07 UTC | #11
Looks like this is the error - still looking:
"Granularity ( P1W ) must evenly divide the specified interval span, accounting for the timezone ( 2016-09-16T19:44:11.726Z/2016-09-23T19:44:11.726Z )."
andygunther | 2016-09-23 19:49:10 UTC | #12
Fixing the interval to this seemed to work:
"interval":"2016-09-16T00:00:00.000Z/2016-09-23T23:59:59.999Z"
andygunther | 2016-09-25 15:18:55 UTC | #13
Is there any way to see what we're sending as the redirectUrl? This is some strange behavior...
This works:
var redirectUrl = window.location.href.substring(0, window.location.href.indexOf("#"));
console.log("Redirect URL: " + redirectUrl);
var pureCloudSession = purecloud.platform.PureCloudSession({ strategy: 'implicit', clientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', redirectUrl: 'http://localhost:8888/foo.html' });
But, this does not, and gives an error that the redirectUrl is not good:
var redirectUrl = window.location.href.substring(0, window.location.href.indexOf("#"));
console.log("Redirect URL: " + redirectUrl);
var pureCloudSession = purecloud.platform.PureCloudSession({ strategy: 'implicit', clientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', redirectUrl: redirectUrl });
The console.log step shows the redirectUrl var is the same thing as the string.
KevinGlinski | 2016-09-26 12:17:38 UTC | #14
The configured value must match exactly so
window.location.href.substring(0, window.location.href.indexOf("#")) === 'http://localhost:8888/foo.html'
should resolve to true. we don't log out the requested redirect urls
andygunther | 2016-09-26 14:47:14 UTC | #15
They match exactly. Here is my console log message:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/6121cca8dd9a39c7fa08d91d996f979e4856547a.png" width="404" height="34">
Here is my code:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/b220e222b7c1eebecaed803d5909cd7cda2a95f7.png" width="630" height="175">
Here is my OAuth Client:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/7e98f8e72e603edcc000d2ad81fa393cd293d569.png" width="464" height="305">
I can't see what I'm missing here...
andygunther | 2016-09-26 14:49:34 UTC | #16
And if I change my code to this, it works:
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/030100852896827023f66645071f514e8b7bc7c3.png" width="637" height="184">
KevinGlinski | 2016-09-26 17:30:53 UTC | #17
what is the actual url that the sdk builds and redirects you to?
andygunther | 2016-09-26 17:33:17 UTC | #18
I'm not following what you're asking?
KevinGlinski | 2016-09-26 17:33:54 UTC | #19
The sdk redirects you to login.mypurecloud.com, what is that full url?
andygunther | 2016-09-26 19:01:57 UTC | #20
When it works:
https://login.mypurecloud.com/?rid=Dv339nE5dDY_2zikidk220PRZi-fayWqO2ENqriujjg#/authenticate-adv/org/theiec
When it doesn't, it's hard to say because it bounces me here:
https://login.mypurecloud.com/#/error?errorKey=invalidRedirectUrl
If I look at the Network trace, it looks like it goes here:
https://login.mypurecloud.com/request
KevinGlinski | 2016-09-26 20:19:32 UTC | #21
There should be a https://login.mypurecloud.com/oauth/authorize... url in between. You'll need to set firefox to persist the network traces so they don't clear on page load.
andygunther | 2016-09-26 21:00:45 UTC | #22
https://login.mypurecloud.com/authorize?&response_type=token&client_id=504d75e6-4465-4f78-8f6e-3d92e285d508
KevinGlinski | 2016-09-26 23:54:48 UTC | #23
what sdk version are you using?
andygunther | 2016-09-27 01:02:17 UTC | #24
I pulled this file from Git on Thursday: purecloud-api-min.js
KevinGlinski | 2016-09-27 13:34:32 UTC | #25
you might need to debug and step into the .login function. There should be a redirecturi querystring param on that url, but I don't know why it isn't there.
andygunther | 2016-09-27 14:31:38 UTC | #26
You're talking about this, correct?:
{ if ("implicit" === this.options.strategy) { var e = this.apiUrl + "/api/v2/users/me";
e isn't being written into the redirectUrl?
KevinGlinski | 2016-09-27 14:34:05 UTC | #27
this function creates the redirecturl https://github.com/MyPureCloud/purecloud_api_sdk_javascript/blob/master/dist/partials/purecloudsession.js#L102
andygunther | 2016-09-27 14:37:22 UTC | #28
Well that's a lot easier to read :slight_smile:
I'll compare the two to see what the difference may be.
andygunther | 2016-09-27 16:01:57 UTC | #29
OK, this turned out to be an issue on my side, not the API. It is now resolved.
However, I still have a question about why this was necessary?
andygunther, post:12, topic:427, full:true
Fixing the interval to this seemed to work:
"interval":"2016-09-16T00:00:00.000Z/2016-09-23T23:59:59.999Z"
KevinGlinski | 2016-09-27 16:23:25 UTC | #30
what did the problem end up being?
for the interval, i'm not sure. Most likely something on the backend service changed between the time the tutorial was written and now.
andygunther | 2016-09-27 16:25:12 UTC | #31
The window.location.href property didn't always have a #, so this was resulting in an empty var:
var redirectUrl = window.location.href.substring(0, window.location.href.indexOf("#"));
I just added this to catch that event:
if (redirectUrl.length == 0) { redirectUrl = window.location.href; }
For the interval - is that a Support issue?
KevinGlinski | 2016-09-27 16:35:33 UTC | #32
No, you just have to make sure your interval is evenly divisible by the granularity
system | 2017-08-28 19:27:29 UTC | #33
This post was migrated from the old Developer Forum.
ref: 427