'Is it possible to programmatically retrieve from serviceaccount credentials which api's are enabled? (in nodejs, not the cloud environment)

I have a service account credentials json file with client_email and private_key. Is it then possible to programmatically retrieve from serviceaccount credentials which api's are enabled? I don't mean a solution like go to console.cloud.google.com but from within nodejs. Thanks!



Solution 1:[1]

You will need to know the Project ID as well. The answer from @wardenunleashed is for API Gateway. That does not cover which Google APIs are enabled.

APIs are enabled per project, so you must specify the project to query.

A service account JSON key file contains the Project ID for the project that owns the service account.

The private_key_id is also important. That ID is used to lookup the public key for validating private key signatures.

Solution 2:[2]

Google has an API Gateway Client Library for NodeJS with the desired capability

const projectId = 'my-project';
const {ApiGatewayServiceClient} = require('@google-cloud/api-gateway');
const client = new ApiGatewayServiceClient();
async function listApis() {
  const [apis] = await client.listApis({
    parent: `projects/${projectId}/locations/global`,
  });
  for (const api of apis) {
    console.info(`name: ${api.name}`);
  }
}
listApis();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Hanley
Solution 2 WardenUnleashed