Node.js error: Route.post() requires a callback function but got a [object Object]

181 views Asked by At

I am running a Node.js script to get a JSON response from Stripe using these instructions https://stripe.com/docs/connect/standard-accounts#token-request

However, I am getting the following error with the below code:

Error: Route.post() requires a callback function but got a [object Object]

Code

var app = express();
var stripe = require('stripe')('sk_test_XXXXXXXXXXXXXXXX')
var bodyParser = require('body-parser')
var request = require('request')

app.post('/ptaccountid',(req,res) => {

  var authCode = req.body.code;

  app.post('https://connect.stripe.com/oauth/token', {
    form: {
     client_secret: "sk_test_XXXXXXXXXXXXXXXX",
     code: authCode,
     grant_type: "authorization_code",
    }
 }, function(err, response, body) {
    if (!err && response.statusCode == 200) {
      console.log(body)
  }
});
}); 
1

There are 1 answers

3
David R On BEST ANSWER

You should be using request.post instead of app.post

Check below code,

app.post('/ptaccountid',(req,res) => {
    var authCode = req.body.code;

    request.post('https://connect.stript.com/oauth/token', {
          form: {
           client_secret: "sk_test_XXXXXXXXXXXXXXXX",
           code: authCode,
           grant_type: "authorization_code",
          }
        }, function(err, response, body) {
          if (!err && response.statusCode == 200) {
            console.log(body)
        }
    });
}); 

Hope this helps!