RPC 'create dataport' returns 'invalid'


#1

I’m trying to use the RPC API to create a dataport on an existing device. I’m using NodeJS with the node-onep library and I have a white label account and a valid CIK for the device. Here is my code:

var auth = {cik: [valid CIK]},
    prettyjson = require('prettyjson'),
    prettyoptions = {noColor: true},
    rpc = require('./rpc');

rpc.callMulti(
  auth,
  [
    {
      procedure: 'info',
      arguments: [{alias: 'flow'}, {}]
    },
    {
      procedure: 'create',
      arguments: ['dataport', {format: 'integer',name: 'Zones On'}]
    }
  ],
  function(err, rpcresponse, httpresponse) {
    if (err) {
      console.log('error: ' + err);
    } else {
      for (i = 0; i < rpcresponse.length; i++)
      {
        console.log('RPC Response:');
        console.log(prettyjson.render(rpcresponse[i], prettyoptions, 2));
      }
    }
  }
);

I receive a normal response from the ‘info’ request, but the ‘create’ request always comes back with ‘invalid’. What am I doing wrong here?


#2

The problem here is that you’re missing the “retention” parameter in your arguments which is a required parameter.

If you look at http://docs.exosite.com/rpc/#create-dataport you’ll see that those parameters don’t have a default (it would show “… = {something}”).

If you replace the second argument with {"format":"integer","name":"Zones On","retention":{"count":5,"duration":"infinity"}} it should work.


#3

Thank you! That was the problem.