Aggregate Query Example Error

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:

Which is odd, because it is here in the javascript, and intellisense seems to understand it's members:

Probably something very stupid on my part - I am not very strong with javascript.

Any thoughts on what I might be missing?

is purecloud-api.min.js successfully loading for you?

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.

your network tab will tell you, the console should also say if it didn't loaded, it does in chrome, not sure about firefox

Yup - 404 Not Found... Huh. I'll have to figure that out I guess :slight_smile:
Thanks!

OK, fixed that, which was bizarre... Now I'm getting the same Not defined error on RoutnigApi, here:

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.

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:

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

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"}]}]}}

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 )."

Fixing the interval to this seemed to work:

"interval":"2016-09-16T00:00:00.000Z/2016-09-23T23:59:59.999Z"

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.

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

They match exactly. Here is my console log message:

Here is my code:

Here is my OAuth Client:

I can't see what I'm missing here...

And if I change my code to this, it works:

what is the actual url that the sdk builds and redirects you to?

I'm not following what you're asking?

The sdk redirects you to login.mypurecloud.com, what is that full url?

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