title: Google Cloud Function; Use Google Cloud Rest APIs
body: <p>The situation is that in my cloud function, I need to create VM instance from an instance template. I was using <code>@google-cloud/compute</code> package, but it doesn't provide a way to do so.</p>
  
  <p>Now, I am trying to use the REST APIs, however I can't get it to authorize. I am using API keys, as instructed on this page <a href="https://cloud.google.com/docs/authentication/api-keys" rel="nofollow noreferrer">Use api keys</a>.</p>
  
  <pre><code>https://www.googleapis.com/compute/v1/projects/&lt;ID&gt;/zones/us-central1-a/instances?key=&lt;API_KEY&gt;&amp;sourceInstanceTemplate=projects/&lt;TEMPLATE_URL&gt;
  </code></pre>
  
  <p>There is a post body as well, but that's irrelevant since the error is with the authorization.</p>
  
  <p><strong>I got <code>login required</code> error.</strong> </p>
  
  <p>I do have a service account that I use with the cloud storage nodejs client on the same cloud function, but I couldn't find documentation on how I could use the same service account with the REST APIs on a cloud function.</p>