vikkey321 | 2016-09-26 17:25:46 UTC | #1
I installed purecloudapisdk_javascript and purecloud and used the below sample code:
// Node.js - Client credentials strategy var pureCloudSession = require('purecloudapisdk_javascript'); var purecloud = require("purecloud");
var session = purecloud.PureCloudSession({ strategy: 'client-credentials', clientId: 'my keys', clientSecret: 'my keys' });
// Browser - Implicit strategy
pureCloudSession.login() .then(function() { // Do authenticated things console.log("authenticated"); });
<img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/56e8b102dbbb6b718737e193a7533f501d2d267d.png" width="690" height="387">
but getting the above error. I tried to search in forum. I am trying to integrate pure node.js application with pure cloud. Is purecloud api provided for node.js stable? or I am doing something wrong?
KevinGlinski | 2016-09-26 17:30:25 UTC | #2
remove line 2, this code is working for me
var purecloud = require('purecloudapisdk_javascript');
var session = purecloud.PureCloudSession({ strategy: 'client-credentials', clientId: process.env.purecloudclientid, clientSecret: process.env.purecloud_secret, timeout: 10000, environment: 'mypurecloud.com' });
session.login()
vikkey321 | 2016-09-26 17:43:40 UTC | #3
Hey Kevin, Thank you very much. I am noobs to purecloud .I followed your suggestion and now, I am not getting any error. Can you tell me how do we write 'after login funcion'. I am trying to write equivalent for this example https://developer.mypurecloud.com/api/tutorials/call-list-management/#javascript .
KevinGlinski | 2016-09-26 17:47:52 UTC | #4
the JS library uses async promises so you need a .then or .error chained after the login. from that tutorial you have
pureCloudSession.login().then(function(){ addContactToList("John Doe", "3172222222"); });
so everything that happens within the
.then(function(){ addContactToList("John Doe", "3172222222"); });
is called after the login succeeds
vikkey321 | 2016-09-26 17:49:47 UTC | #5
KevinGlinski, post:4, topic:433
hing that
Thank you Again for quick response. See <img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/3e56a370f49a2723255702ccdbd0732bb7b3d05f.png" width="690" height="387"> Still facing issue with that
var purecloud = require('purecloudapisdk_javascript');
var session = purecloud.PureCloudSession({ strategy: 'client-credentials', clientId: 'xx', clientSecret: 'xx', timeout: 10000, environment: 'mypurecloud.com' });
purecloud.login() .then(function() { // Do authenticated things console.log("authenticated"); });
KevinGlinski | 2016-09-26 17:50:28 UTC | #6
should be session.login()
vikkey321 | 2016-09-26 18:04:33 UTC | #7
Thank youl. This is another related issue which I have been facing when I tried this around a week back: <img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/239bdf43c6602603751f5fe7ba3a4a1572ecdea0.png" width="690" height="387"> var purecloud = require('purecloudapisdk_javascript');
var session = purecloud.PureCloudSession({ strategy: 'client-credentials', clientId: 'xx', clientSecret: 'xx', timeout: 10000, environment: 'mypurecloud.com' });
var outboundApi = new OutboundApi(purecloud); var notificationsapi = new NotificationsApi(purecloud);
function addContactToList(name, number){ var contactData = [ { "contactListId": contactListId, "data": { "Name": name, "Number": number }, "callable": true } ];
outboundApi.postContactlists.ContactlistId.Contacts(contactListId, contactData, true).then(function(){ console.log("contact added to list") }); }
session.login().then(function() { // Do authenticated things addContactToList("John Doe", "3172222222"); });
vikkey321 | 2016-09-26 19:51:02 UTC | #8
I maybe wrong, but even after using your code, it doesn't gives any error or response. The samples provided in node.js by purecloud, most of them don't work.
KevinGlinski | 2016-09-26 20:14:49 UTC | #9
The .then function isn't being called?
vikkey321 | 2016-09-27 01:43:53 UTC | #10
.then function is being called directly.
KevinGlinski | 2016-09-27 01:46:39 UTC | #11
that means you have an authenticated session, what is it not doing that you are expecting it to do?
vikkey321 | 2016-09-27 01:48:04 UTC | #12
I am writing a program to initiate simple login, and will print something after login is succesfull.
system | 2017-08-28 19:27:31 UTC | #13
This post was migrated from the old Developer Forum.
ref: 433