kylas
kylas

Reputation: 1455

How do I pass in url parameter using request.get?

Actual api should be like below:

https://.../api/v1/users/getprofile?access_token={{access_token}} 

Below is how I am trying to call the API using request

 const request = require('request'); 



request.get("https://.../api/v1/users/getProfile?accessToken=",{accessToken: req.query.accessToken})

However, it failed. How can I print out whats the url being called ? And how can I fix the error ?

Upvotes: 1

Views: 51

Answers (2)

SPlatten
SPlatten

Reputation: 5760

Try this:

    const request = require('request'); 

    try {
        var strURI = encodeURI("https://.../api/v1/users/getProfile?accessToken=");
        request.get(strURI, {accessToken: req.query.accessToken});
    } catch(e) {
        console.log("Exception: " + e.message);
    }

Upvotes: 1

sajan
sajan

Reputation: 1370

You can use something like this.

const request = require("request")
request.get({url: "http://.../api/v1/users/getprofile", qs: {"accessToken": "xxxxx"}}, function(err, response, body) {
    console.log(err, body);
})

Upvotes: 1

Related Questions