title: Trigger a cloud build pipeline using Cloud Function
body: <p>I'm trying to create a cloud function listening to cloudbuilds topic and making an API call to trigger the build. I think I'm missing something in my index.js file (I'm new to Node.js). Can you provide a sample example of a Cloud Function making an API call to the Cloud Build API?</p>
  
  <p>Here is my function:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>const request = require('request')
  
  const accessToken = '$(gcloud config config-helper --format='value(credential.access_token)')';
  
  request({
    url: 'https://cloudbuild.googleapis.com/v1/projects/[PROJECT_ID]/builds',
    auth: {
      'bearer': accessToken
    },
    method: 'POST',
    json: {"steps": [{"name":"gcr.io/cloud-builders/gsutil", "args": ['cp','gs://adolfo-test-cloudbuilds/cloudbuild.yaml', 'gs://adolfo-test_cloudbuild/cloudbuild.yaml']}]},
  }, 
  module.exports.build = (err, res) =&gt; {
    console.log(res.body);
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>I was executing the command <code>gcloud config config-helper --format='value(credential.access_token)'</code>, copying the token, and putting it as a value to the variable accessToken. But this didn't work for me.   </p>
  
  <p>Here is the error: <code>{ error: { code: 403, message: 'The caller does not have permission', status: 'PERMISSION_DENIED' } }</code></p>