4

I have my optional parameter defined using my param function below, but when I try Postman passing in the optional parameter I get a Reference Error 'off' is not defined. I can't figure out how to use the value I pass in for the parameter in the second function below, and I'm assuming my incorrect usage of it is what's causing the error. I'm attempting to define my parameter in the first function.

router.param('off', function(req, res, next, off){
  req.offset = off;
  next();
});

I am defining my route with the optional param here

router.get('/messages/:offset',  function(request, res) {
    ctxioClient.accounts(ID).messages().get({limit: 100, offset: off},
    function ( err, response) {

    )};
)};
Rafa
  • 2,566
  • 3
  • 31
  • 58

1 Answers1

5

Optional parameters are defined with a ?

router.get('/messages/:offset?',  function(request, res) {
  var offset = req.params.offset || 0;
  // make 0 if no offset is present
  ctxioClient.accounts(ID).messages().get({limit: 100, offset: offset},
  function ( err, response) {

  )};
)};
jshawl
  • 2,828
  • 2
  • 19
  • 31