Cannot get devices list with Tenant API key

Hello, I am trying to use the gRPC API to retrieve device info from Chirpstack in a python script.
I have created 2 API keys:

  • 1 global created under Network Server
  • 1 created in a Tenant

When using ListGatewaysRequest(), I can specify the tenant_id, so the request works with both key

However, when using ListDevicesRequest(), I am not able to specify the tenant_id and it only works with the global key. With the Tenant key i get this error:

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAUTHENTICATED
	details = ""
	debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"", grpc_status:16, created_time:"2024-01-05T09:16:03.2162155+00:00"}"

I have also tried to add an application_id filter (with an application that is within my Tenant), but it still does not work.

Am I doing something wrong ?

Here is the code that I have used:

import os
import sys

import grpc
from chirpstack_api import api

server = "...:8080"

api_token = "..."

channel = grpc.insecure_channel(server)

def get_gw_list():

  client = api.GatewayServiceStub(channel)

  auth_token = [("authorization", "Bearer %s" % api_token)]

  req = api.ListGatewaysRequest()
  req.tenant_id = '00000000-0000-0000-0000-000000000009'
  req.limit = 1000

  resp = client.List(req, metadata=auth_token)

  return resp

def get_devices_list():

  client = api.GatewayServiceStub(channel)

  auth_token = [("authorization", "Bearer %s" % api_token)]

  req = api.ListDevicesRequest()
  req.application_id = '00000000-0000-0000-0000-000000000071'
  req.limit = 1000 

  resp = client.List(req, metadata=auth_token)

  return resp


Thank you in advance.

Indeed, the description of the API is lacking details on this.
I would assume that it allows to work by Tenant otherwise its usefulness would be limited.

@brocaar is there other detailed document on the API detailing its usage per tenant

The only way to get them all with admin key is searching for all the tenant id’s then search each tenant id for application ids then get devices per the application id.

from a tenant level key it would be search by application id’s then get all devices from each application.

it would make life easy if admin key could return all devices and tenant key return all tenant devices… i guess there is/was a reason why. I usually get them all directly from the chirp postgres db as it saves a stack of api/rpc calls.