AssertionError: params must be an array

483 views
Skip to first unread message

Karthick Thoppe

unread,
Apr 20, 2017, 7:25:11 AM4/20/17
to LoopbackJS
Hi all,

I have two remote methods with single/multiple parameters and when I invoke the API, I get the following error; any ideas?

Thanks in advance!

{ "error": { "statusCode": 500, "name": "AssertionError", "message": "params must be an array", "actual": false, "expected": true, "operator": "==", "generatedMessage": false, "stack": "AssertionError: params must be an array\n ..... " } }

My remote method code set:

Lsagrmnt.getTestContract = function (agreementId, cb){ var ds = Lsagrmnt.dataSource; var sql = "SELECT top 1 LS_AGRMNT_NR FROM LS_AGRMNT WHERE LS_AGRMNT_ID = ?"; ds.connector.query(sql, agreementId, function (err, test) { if (err) console.error(err); cb(err, test); } ); };

Lsagrmnt.remoteMethod( 'getTestContract', { http: { path: '/getTestContract', verb: 'get' }, description : 'Test with one filter', accepts: { arg: 'agreementId', type: 'number'}, returns: { arg: 'data', type: ['string'], root: true } } );

Francois Laforge

unread,
Apr 24, 2017, 11:22:08 AM4/24/17
to loopb...@googlegroups.com
How are you passing your parameters?  You're using a GET verb for your remote method which does not accept parameters in the body of hte call as far as I know.  For a GET you need to pass the parameters in the URL (path).  use either:

URL:  ~/12345678/getTestContract

Lsagrmnt.remoteMethod(
  'getTestContract', {
    http: {
      path: '/:agreementId/getTestContract',
      verb: 'get'
    },
    description : 'Test with one filter',
    accepts: { arg: 'agreementId', type: 'number'},
    returns: {
      arg: 'data',
      type: ['string'],
      root: true
    }
  }
);

or

URL:  ~/getTestContract?agreementId=12345678

Lsagrmnt.remoteMethod(
  'getTestContract', {
    http: {
      path: '/getTestContract',
      verb: 'get'
    },
    description : 'Test with one filter',
    accepts: { arg: 'agreementId', type: 'number', http:{source: 'query'}},
    returns: {
      arg: 'data',
      type: ['string'],
      root: true
    }
  }
);


Your path should look like this for a get:  /:agreementId/getTestContract

Raymond Feng

unread,
Apr 24, 2017, 11:37:34 AM4/24/17
to loopb...@googlegroups.com
Please use ds.connector.query(sql, [agreementId], function (err, test) {}. The parameterized SQL execution requires an array of values.

Thanks,
Raymond

On Apr 24, 2017, at 8:22 AM, Francois Laforge <francois...@gmail.com> wrote:

How are you passing your parameters?  You're using a GET verb for your remote method which does not accept parameters in the body of hte call as far as I know.  For a GET you need to pass the parameters in the URL (path).  use either:

URL:  ~/abcd1234/getTestContract

Lsagrmnt.remoteMethod(
  'getTestContract', {
    http: {
      path: '/:agreementId/getTestContract',
      verb: 'get'
    },
    description : 'Test with one filter',
    accepts: { arg: 'agreementId', type: 'number'},
    returns: {
      arg: 'data',
      type: ['string'],
      root: true
    }
  }
);

or

URL:  ~/getTestContract?agreementId=abcd1234

Lsagrmnt.remoteMethod(
  'getTestContract', {
    http: {
      path: '/getTestContract',
      verb: 'get'
    },
    description : 'Test with one filter',
    accepts: { arg: 'agreementId', type: 'number', http:{source: 'query'}},
    returns: {
      arg: 'data',
      type: ['string'],
      root: true
    }
  }
);


Your path should look like this for a get:  /:agreementId/getTestContract

On Thursday, April 20, 2017 at 7:25:11 AM UTC-4, Karthick Thoppe wrote:
Hi all,

I have two remote methods with single/multiple parameters and when I invoke the API, I get the following error; any ideas?

Thanks in advance!

{ "error": { "statusCode": 500, "name": "AssertionError", "message": "params must be an array", "actual": false, "expected": true, "operator": "==", "generatedMessage": false, "stack": "AssertionError: params must be an array\n ..... " } }

My remote method code set:

Lsagrmnt.getTestContract = function (agreementId, cb){ var ds = Lsagrmnt.dataSource; var sql = "SELECT top 1 LS_AGRMNT_NR FROM LS_AGRMNT WHERE LS_AGRMNT_ID = ?"; ds.connector.query(sql, agreementId, function (err, test) { if (err) console.error(err); cb(err, test); } ); };

Lsagrmnt.remoteMethod( 'getTestContract', { http: { path: '/getTestContract', verb: 'get' }, description : 'Test with one filter', accepts: { arg: 'agreementId', type: 'number'}, returns: { arg: 'data', type: ['string'], root: true } } );

-- 
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/loopbackjs/36b86ae0-27ee-45af-8edb-88971d985ee9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages