Google Cloud IoT Core is being retired on August 16, 2023. Contact your Google Cloud account team for more information.

List gateways for device

Stay organized with collections Save and categorize content based on your preferences.

List all of a device's gateways.

Code sample


For more information, see the Cloud IoT Core Node.js API reference documentation.

// const cloudRegion = 'us-central1';
// const deviceId = 'my-device';
// const projectId = 'adjective-noun-123';
// const registryId = 'my-registry';
const iot = require('@google-cloud/iot');
const iotClient = new iot.v1.DeviceManagerClient({
  // optional auth parameters.

async function listDevices() {
  // Construct request
  const parentName = iotClient.registryPath(

  const [response] = await iotClient.listDevices({
    parent: parentName,
    gatewayListOptions: {associationsDeviceId: deviceId},
  const devices = response;

  if (devices.length > 0) {
    console.log('Current gateways for: ', deviceId);
  } else {
    console.log('No gateways associated with this device.');

  for (let i = 0; i < devices.length; i++) {
    const device = devices[i];
    console.log(`\tDevice: ${device.numId}: ${}`);


What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.