gRPC and Error-Code 3 invalid length while executing CreateDeviceRequest

Hi Guys,

i don’t have a clue, what issue i am running into. I am trying to add devices to my ChirpStack Applications.

But i am ending up with this error message:
Error: 3 INVALID_ARGUMENT: invalid length: expected length 32 for simple format, found 0

My Code:

// Imports
const grpc = require("@grpc/grpc-js");
const device_grpc = require("@chirpstack/chirpstack-api/api/device_grpc_pb");
const device_pb = require("@chirpstack/chirpstack-api/api/device_pb");

// Create the client for the DeviceService.
const deviceService = new device_grpc.DeviceServiceClient(
    "localhost:8080",
    grpc.credentials.createInsecure(),
);

// Create the Metadata object.
const metadata = new grpc.Metadata();
metadata.set("authorization", "Bearer " + apiToken);

// Device
let ChripStackDevice = new device_pb.Device();
ChripStackDevice.getTagsMap().set('meter_id', 'Nr. 123456');
ChripStackDevice.getTagsMap().set('area_id', '14');
ChripStackDevice.getTagsMap().set('area', 'First Street');
ChripStackDevice.setDescription('Water Meter Nr. 123456 in Area "First Street" #14');
ChripStackDevice.setApplicationId( 4760083592357697419966480933974487906 );
ChripStackDevice.setDeviceProfileId( '286385887245725194742603190578555332218' );
ChripStackDevice.setDevEui('0001020304050607');
ChripStackDevice.setName('Meter-123456');
ChripStackDevice.setSkipFcntCheck(true);
ChripStackDevice.setIsDisabled(false);

// Create Request
let ChripStackCreateDeviceRequest = new device_pb.CreateDeviceRequest();
ChripStackCreateDeviceRequest.setDevice(ChripStackDevice);
deviceService.create( ChripStackCreateDeviceRequest, metadata, (err, resp) => {
	if (err !== null)
	  throw err;
  
	console.log("Device has been added with id: " + resp.getId());
});

Dumped Object and Error Message:

{
  wrappers_: {
    '1': {
      wrappers_: {
        '9': {
          arr_: [
            [ 'area', 'First Street' ],
            [ 'area_id', '14' ],
            [ 'meter_id', 'Nr. 123456' ]
          ],
          valueCtor_: null,
          map_: {
            meter_id: {
              key: 'meter_id',
              value: 'Nr. 123456',
              valueWrapper: undefined
            },
            area_id: { key: 'area_id', value: '14', valueWrapper: undefined },
            area: {
              key: 'area',
              value: 'First Street',
              valueWrapper: undefined
            }
          },
          arrClean: true
        }
      },
      messageId_: undefined,
      arrayIndexOffset_: -1,
      array: [
        '0001020304050607',
        'Meter-123456',
        'Water Meter Nr. 123456 in Area "First Street" #14',
        4.7600835923576974e+36,
        '286385887245725194742603190578555332218',
        true,
        null,
        <1 empty item>,
        [
          [ 'area', 'First Street' ],
          [ 'area_id', '14' ],
          [ 'meter_id', 'Nr. 123456' ]
        ]
      ],
      pivot_: 1.7976931348623157e+308,
      convertedPrimitiveFields_: {}
    }
  },
  messageId_: undefined,
  arrayIndexOffset_: -1,
  array: [
    [
      '0001020304050607',
      'Meter-123456',
      'Water Meter Nr. 123456 in Area "First Street" #14',
      4.7600835923576974e+36,
      '286385887245725194742603190578555332218',
      true,
      null,
      <1 empty item>,
      [
        [ 'area', 'First Street' ],
        [ 'area_id', '14' ],
        [ 'meter_id', 'Nr. 123456' ]
      ]
    ]
  ],
  pivot_: 1.7976931348623157e+308,
  convertedPrimitiveFields_: {}
}
/home/rack/import-zenner.js:41
        throw err;
        ^

Error: 3 INVALID_ARGUMENT: invalid length: expected length 32 for simple format, found 0
    at callErrorFromStatus (/home/rack/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/home/rack/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
    at Object.onReceiveStatus (/home/rack/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/home/rack/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /home/rack/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
    at processTicksAndRejections (internal/process/task_queues.js:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/home/rack/node_modules/@grpc/grpc-js/build/src/client.js:160:34)
    at ServiceClientImpl.create (/home/rack/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at Object.<anonymous> (/home/rack/import-zenner.js:38:15)
    at Module._compile (internal/modules/cjs/loader.js:1114:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47 {
  code: 3,
  details: 'invalid length: expected length 32 for simple format, found 0',
  metadata: Metadata {
    internalRepr: Map(3) {
      'content-type' => [ 'application/grpc' ],
      'content-length' => [ '0' ],
      'date' => [ 'Sat, 08 Apr 2023 18:59:34 GMT' ]
    },
    options: {}
  }

Hi,
There is a mandatory field that is not provided.
Maybe you could first try by adding quotes to wrap the AppID (it is an int in your code).

oooookay, you pointed me to the right direction. But why is the error message so unclear to the missing / incorrect data provided? There should be more verbose output like “application-id - invalid length - expect 32 for simple format, got 0

application_id has to be the UUID without the dashes.

The documentation says int64.

You are looking at v3 API specification. Please see the v4 API documentation:

https://www.chirpstack.io/docs/chirpstack/api/api.html#api-Device

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.