return a value from azure function to another function nodejs

Viewed 28

I am trying to get a value from another azure function within another azure function.

When I call this function from postman I get the correct response. I get the accessToken. But when I call the same function in code and assign it to a variable it just becomes a big weird object.

const request = require("request");

module.exports = function GetAuth(context, req) {
context.log('JavaScript HTTP trigger function processed a request.');

var url = "myurl.com";

clientId = "****";

clientSecret = "****";

tenantId = "****";

const requestParams = {
    grant_type: "client_credentials",
    client_id: clientId,
    client_secret: clientSecret,
    resource: "https://graph.windows.net"
};

request.post({ url: url, form: requestParams }, function (err, response, body) {
    if (err) {
        console.log("error");
    }
    else {
        let parsedBody = JSON.parse(body);         
        if (parsedBody.error_description) {
            console.log("Error=" + parsedBody.error_description);
        }
        else {
            context.res = {
                body: parsedBody.access_token
            };
            context.done();
        }
    }
});
}

This is how I am calling the function.

module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');

const accessToken = request.get("http://localhost:7071/api/GetAuth");

console.log(accessToken);
}

I don't quite know how to get it from the GetAuth function to the other function.

Any help is appreciated.

0 Answers
Related