title: Google Analytics API: Uncaught TypeError: Cannot read property 'request' of undefined
body: <p>I have been looking for a solution to this, but since I'm a newbie I might be missing something obvious? I'm playing with the Quick Start example, trying to set a batch request, because I'm trying to learn how they work :).</p>
  
  <p>This is the code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
  
    &lt;title&gt;Batching test&lt;/title&gt;
  &lt;meta charset="utf-8"&gt;
   &lt;meta name="google-signin-client_id" content="&lt;MyID&gt;"&gt;
   &lt;meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics.readonly"&gt;
   &lt;!-- Load the JavaScript API client and Sign-in library. --&gt;
    &lt;script src="https://apis.google.com/js/client:platform.js""&gt;&lt;/script&gt;
    &lt;!--&lt;script src="/batching/script.js"&gt;&lt;/script&gt;--&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Hello Analytics Reporting API V4&lt;/h1&gt;
  
  &lt;!-- The Sign-in button. This will run `queryReports()` on success. --&gt;
  &lt;p class="g-signin2" data-onsuccess="batchExecution"&gt;&lt;/p&gt;
  &lt;script&gt;
      var VIEW_ID = '3213999';
  
  var sessionsM = 'ga:sessions';
  var transactionsM = 'ga:transactions';
    // Query the API and print the results to the page.
  /*gapi.analytics.ready(function() {
    console.log('hi');
    });*/
    var analyticsReportRequest = function queryReports(chooseMetric) {
      gapi.client.request({
        path: '/v4/reports:batchGet',
        root: 'https://analyticsreporting.googleapis.com/',
        method: 'POST',
        body: {
          reportRequests: [
            {
              viewId: VIEW_ID,
              dateRanges: [
                {
                  startDate: '7daysAgo',
                  endDate: 'today'
                }
              ],
              metrics: [
                {
                  expression: choseMetric
                }
              ]
            }
          ]
        }
      }).then(displayResults, console.error.bind(console));
    };
  
  var report1 = analyticsReportRequest(sessionsM);
  var report2 = analyticsReportRequest(transactionsM);
  function batchExecution() {
    var batch = gapi.client.newBatch();
     batch.add(report1);
     batch.add(report2);
  }
  
  
  
  
    function displayResults(response) {
      var formattedJson = JSON.stringify(response.result, null, 2);
      document.getElementById('query-output').value = formattedJson;
    }
  &lt;/script&gt;
  &lt;!-- The API response will be printed here. --&gt;
  &lt;textarea cols="80" rows="20" id="query-output"&gt;&lt;/textarea&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm getting the following errors (file name is index.html): 
  First Error:</p>
  
  <pre><code>(index):31 Uncaught TypeError: Cannot read property 'request' of undefined
      at queryReports ((index):31)
      at (index):56
  </code></pre>
  
  <p>Second error:</p>
  
  <pre><code>cb=gapi.loaded_0:73 Uncaught wY {message: "Batch entry is missing a request method", stack: "gapi.client.Error: Batch entry is missing a reques…zhnSLA1FmTcs72V1b-s3Z55A/cb=gapi.loaded_0:77:300)"}
  </code></pre>
  
  <p>Could someone potentially help me, please?</p>
  
  <p>Many thanks,
  J.</p>