Legacy Dev Forum Posts

 View Only

Sign Up

Nodejs Oauth grant access problem

  • 1.  Nodejs Oauth grant access problem

    Posted 06-05-2025 19:19

    vikkey321 | 2016-09-28 15:27:19 UTC | #1

    My credentials are configured as client credentials and granted full access. But it gives a 403 error. Tried removing auth, then it gives a 400 error. Here is my code

    var purecloud = require('purecloudapisdk_javascript');

    var session = purecloud.PureCloudSession({ strategy: 'client-credentials', clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', timeout: 2000, environment: 'mypurecloud.com/oauth' });

    var contactListId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; var campaignId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

    var outboundApi = new purecloud.OutboundApi(session);

    function addContactToList(name, number){ var contactData = [ { "contactListId": contactListId, "data": { "Name": name, "Number": number }, "callable": true } ];

    outboundApi.postContactlistsContactlistIdContacts(contactListId, contactData, true).then(function(){ console.log("contact added to list") }).catch(function(err){ console.error("ERROR", err); }); }

    function startCampaign(){ //get campaign information outboundApi.getCampaign(campaignId).then(function(campaignInfo){ //if campaign is not on, update it so it is on. if(campaignInfo.campaignStatus !== "on"){ data.campaignStatus = "on"; outboundApi.postCampaigns(campaignId, data); }

    }); }

    session.login() .then(function() { // Do authenticated things addContactToList("John Doe", "3172222222");

    //console.log("successful"); }).catch(function(err){ console.error("ERROR", err); });


    KevinGlinski | 2016-09-28 15:40:38 UTC | #2

    /oauth should not be on the environment parameter, what is the details of the 400 error?


    vikkey321 | 2016-09-28 15:43:48 UTC | #3

    text: '{"error":"invalid_client"}\n',

    The credentials are configured as client credentials.


    KevinGlinski | 2016-09-28 17:13:56 UTC | #4

    what happens if you leave oauth in place, then after you are logged in session.setEnvironment('mypurecloud.com'); then call outboundApi.postContactlistsContactlistIdContacts


    vikkey321 | 2016-09-29 03:29:01 UTC | #5

    KevinGlinski, post:4, topic:447
    leave oa

    It shows me 400 error


    vikkey321 | 2016-09-29 04:47:36 UTC | #6

    It is giving error 405.


    KevinGlinski | 2016-09-29 12:16:54 UTC | #7

    I need more specifics to help you out, what is the error body and what method call is returning the error?


    vikkey321 | 2016-09-29 12:47:52 UTC | #8

    Now, I am trying to do as per showed in javascript example of outbound api using implicit. var purecloud = require('purecloudapisdk_javascript');

    var session = purecloud.PureCloudSession({ strategy: 'implicit', clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx', environment: 'mypurecloud.com' });

    var contactListId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; var campaignId = "xxxxxxxxxxxxxxxxxxxxxxxxxx";

    var outboundApi = new purecloud.OutboundApi(session);

    function addContactToList(name, number){ var contactData = [ { "contactListId": contactListId, "data": { "Name": name, "Number": number }, "callable": true } ];

    outboundApi.postContactlistsContactlistIdContacts(contactListId, contactData, true).then(function(){ console.log("contact added to list") }).catch(function(err){ console.error("ERROR", err); }); }

    function startCampaign(){ //get campaign information outboundApi.getCampaign(campaignId).then(function(campaignInfo){ //if campaign is not on, update it so it is on. if(campaignInfo.campaignStatus !== "on"){ data.campaignStatus = "on"; outboundApi.postCampaigns(campaignId, data); }

    }); }

    session.login() .then(function() { // Do authenticated things addContactToList("John Doe", "3172222222");

    //console.log("successful"); }).catch(function(err){ console.error("ERROR", err); });

    and here is the error currently: <img src="//inin-prod-use1-developerforum.s3.amazonaws.com/original/1X/d520c7302739a9f45189a3a3a2c919774bf7181c.png" width="690" height="387">


    KevinGlinski | 2016-09-29 23:25:23 UTC | #9

    you can't use the implicit login in a node app


    chuck.pulfer | 2016-09-30 02:47:08 UTC | #10

    The OAuth implicit and code authorization grants require the user to enter their credentials on the PureCloud login web page (login.mypurecloud.com). If an application is making api calls in a user context then the user needs to enter their credentials to prove their identity.

    A node web server could use the code authorization grant by redirecting the user to the PureCloud login page. https://developer.mypurecloud.com/api/rest/authorization/use-authorization-code.html

    If your application is strictly a service/bot and doesn't need to operate in the context of a user then it can use the client credentials grant.


    system | 2017-08-28 19:27:36 UTC | #11


    This post was migrated from the old Developer Forum.

    ref: 447