Thursday, 1 June 2017

unable to print post response

I'm writing a program in node js that does the following.

  1. Get the Access token(a jwt)
  2. Get the user firstName from that token
  3. Pass this token and firstName to another method to post.
  4. print the result.

My program is as below.

function getUserDetailsFromAccessToken(session) {

    var token = session.user.accessToken;
    try {
        // parse this and get user attributes
        var decoded = jwt.decode(token);
        getTheUserProfile(decoded.firstname, token, session);
    } catch (err) {
        console.log(err);
    }
}

var hostUrl= "myUrlToGetResult";

function getTheUserProfile(nameFromSession, token) {
    console.log("Incomung values " + nameFromSession);
    console.log("Inside getUsersProfile Block");
    var jsonToPass = {
        "accesstoken": token,
        "domain": "DomainName",
        "lanid": nameFromSession
    };
    console.log("json to pass " + JSON.stringify(jsonToPass));

    var options = {
        uri: hostUrl+ "/api/admin/GetUserInfo",
        method: "POST",
        json: jsonToPass
    };
    request(options, function (error, resp, body) {

        if (!error && resp.statusCode == 200) {
            if (body) {
                console.log("Insode B1");
                console.log(body.firstName);
            } else {
                console.log("I am unable to authenticate you. please disable the skill and re link your account");
            }
        } else {
            console.log(error);
        }

    });
}

when I run this program, I'm able to print only till console.log("json to pass " + JSON.stringify(jsonToPass));, after that I'm unable to get any result from request() block.

please let me know where am I going wrong and how can I fix it.



via user3872094

No comments:

Post a Comment