title: GCP API Client Libraries Java Examples - com.google.api.services.deploymentmanager.DeploymentManager
body: <p>I am looking to automate the provisioning of google cloud resources using Deployment Manager. Only I want to use the JAVA API library instead of gcloud.</p>
  <p>Specifically need to provision the following components using DeploymentManager.</p>
  <ol>
  <li>Cloud SQL - MSSQL</li>
  <li>Cloud Run Service</li>
  <li>VPC Network with the Connector to be used to connect Cloud Run to the Cloud SQL.</li>
  </ol>
  <p>I think <code>com.google.api.services.deploymentmanager.DeploymentManager</code> is the starting point but I am not very sure.</p>
  <p>This is what I have so far</p>
  <pre><code>
          Builder builder = new Builder(
                  com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(),
                  new com.google.api.client.json.gson.GsonFactory(), null);
          builder.setApplicationName(&quot;spatial-cat-319209&quot;);
          builder.setDeploymentManagerRequestInitializer(new DeploymentManagerRequestInitializer());
          DeploymentManager deploymentManager = builder.build();
  
          deploymentManager.deployments().list(&quot;spatial-cat-319209&quot;).entrySet().stream().forEach(entry -&gt; {
              System.out.println(entry.getKey() + &quot; = &quot; + entry.getValue());
          });
          
          System.out.println(System.getProperty(&quot;GOOGLE_APPLICATION_CREDENTIALS&quot;));
          System.out.println(System.getenv(&quot;GOOGLE_APPLICATION_CREDENTIALS&quot;));
          
          deploymentManager.deployments().list(&quot;spatial-cat-319209&quot;).execute();
  
  </code></pre>
  <p>I get the following error in the last line:</p>
  <pre><code>Exception in thread &quot;main&quot; com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
  GET https://deploymentmanager.googleapis.com/deploymentmanager/v2/projects/spatial-cat-319209/global/deployments
  {
    &quot;code&quot;: 401,
    &quot;errors&quot;: [
      {
        &quot;domain&quot;: &quot;global&quot;,
        &quot;location&quot;: &quot;Authorization&quot;,
        &quot;locationType&quot;: &quot;header&quot;,
        &quot;message&quot;: &quot;Login Required.&quot;,
        &quot;reason&quot;: &quot;required&quot;
      }
    ],
    &quot;message&quot;: &quot;Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.&quot;,
    &quot;status&quot;: &quot;UNAUTHENTICATED&quot;
  }
      at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
      at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:118)
      at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:37)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:428)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1111)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:514)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:455)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:565)
  </code></pre>
  <p>I do have the environment variable GOOGLE_APPLICATION_CREDENTIALS pointing to a file that contains the service account key (generated using <code>gcloud auth application-default login</code> command)</p>
  <p>Any insights would be very helpful.</p>