title: Google Cloud Search Query via Node.js Error: This project doesn't have Cloud Search's Query API Enabled
body: <p>I am working on Google Cloud Search API to search documents stored in Google Drive. I have Google Workspace account and few documents stored in Google Drive. I am able to search using Google Cloud search console but facing issue using below node.js code for searching using API.</p>
  <p>Issue: I am able to generate the access token but get below error for search query:</p>
  <blockquote>
  <p>Error: This project doesn't have Cloud Search's Query API Enabled,
  and/or the Cloud Search Platform license has not been assigned to the
  user account calling the Query API</p>
  </blockquote>
  <pre><code>var {google} = require(&quot;googleapis&quot;);
  
  var serviceAccount  = require('C:/nodejstest/key/serviceAccountKey.json');
  
  // Specify the required scope.
  var scopes = [
      &quot;https://www.googleapis.com/auth/cloud_search&quot;,
      &quot;https://www.googleapis.com/auth/cloud_search.query&quot;
    ];
  
  var jwtClient = new google.auth.JWT({
    email: serviceAccount.client_email,
    key: serviceAccount.private_key,
    scopes: scopes,
    subject: 'sample@example.com'
  });
  
  // Use the JWT client to generate an access token.
  jwtClient.authorize(function(error, tokens) {
      if (error) {
        console.log(&quot;Error making request to generate access token:&quot;, error);
      } else if (tokens.access_token === null) {
        console.log(&quot;Provided service account does not have permission to generate access tokens&quot;);
      } else {
        var accessToken = tokens.access_token;
        console.log('accessToken= ' + accessToken)
        // Include the access token in the Authorization header.
      }
    });
  
  
  const service = google.cloudsearch({version: 'v1'});
  service.query.search({
      auth: jwtClient,
      requestBody: {
        requestOptions: {
          searchApplicationId: 'searchapplications/default',
          debugOptions:{enableDebugging: true}
        },
        query: 'My query'
      }
    }).then((res) =&gt; {
    console.log(JSON.stringify({results:res.results.length}));
    console.log(JSON.stringify({resultsInfo:res.results[0]}));
  }).catch((err) =&gt; {
    console.error('Unexpected error with cloud search API.');
    console.error(err.toString());
  });
  </code></pre>
  <p>In above code I am passing workspace admins email id as subject.</p>
  <p>I followed steps mentioned at below link</p>
  <ul>
  <li><a href="https://developers.google.com/cloud-search/docs/guides/project-setup" rel="nofollow noreferrer">Configure access to the Google Cloud Search REST API</a></li>
  <li><a href="https://developers.google.com/cloud-search/docs/guides/delegation/" rel="nofollow noreferrer">Perform Google Workspace domain-wide delegation of authority</a></li>
  </ul>