Update
It appears that currently, when you don't explicitly load the API from the discovery document, the NodeJS client library is having issues with IoT.
To work around this for now, do the following to initialize your API client:
const serviceAccountJson = `/home/class/iot_creds.json`;
const API_VERSION = 'v1';
const DISCOVERY_API = 'https://cloudiot.googleapis.com/$discovery/rest';
function getClient (serviceAccountJson, cb) {
const serviceAccount = JSON.parse(fs.readFileSync(serviceAccountJson));
const jwtAccess = new google.auth.JWT();
jwtAccess.fromJSON(serviceAccount);
// Note that if you require additional scopes, they should be specified as a
// string, separated by spaces.
jwtAccess.scopes = 'https://www.googleapis.com/auth/cloud-platform';
// Set the default authentication to the above JWT access.
google.options({ auth: jwtAccess });
const discoveryUrl = `${DISCOVERY_API}?version=${API_VERSION}`;
google.discoverAPI(discoveryUrl, {}, (err, client) => {
if (err) {
console.log('Error during API discovery', err);
return undefined;
}
cb(client);
});
}
Original
The NodeJS management sample currently uses the Google API client (e.g. "googleapis": "20.1.0"
in package.json) library and not a separate library.
If you haven't already, try running the sample locally as described in the sample readme:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
cd nodejs-docs-samples/iot/manager
npm install
node manager.js
If the sample doesn't work locally, please let us know the node version (node --version
) and installed modules versions (output of package.lock or npm ls
).
If the sample works locally for you (after running npm install
) then the issue is with how the sample is being executed from the Cloud functions backend.