title: Integrating MATLAB with Google BigQuery via REST API
body: <p>I'm trying to use MATLAB's webread function to query Google BigQuery via the REST API, and am having issues. The following curl request is successful:</p>
  
  <pre><code>curl 'https://www.googleapis.com/bigquery/v2/projects/&lt;MyProjectId&gt;/queries' \
    -X POST \
    -H 'Authorization: Bearer &lt;MyBearerToken&gt;' \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    --data-binary '{"query":"select count(1) from MyTable","useLegacySql":false}' \
    --compressed
  </code></pre>
  
  <p>However, the following MATLAB code:</p>
  
  <pre><code>api = 'https://www.googleapis.com/bigquery/v2/';
  access_token = '&lt;MyAccessToken&gt;';
  options = weboptions('RequestMethod', 'post');
  r = webread([api 'projects/&lt;MyProjectId&gt;/queries?access_token=' access_token], ...
      'query', 'select count(1) from MyTable', ...
      'useLegacySql', false, ...
      options);
  </code></pre>
  
  <p>generates the following error:</p>
  
  <pre><code>Error using readContentFromWebService (line 45)
  The server returned the status 400 with message "Bad Request" in response to the request to URL
  https://www.googleapis.com/bigquery/v2/projects/&lt;MyProjectId&gt;/queries?access_token=&lt;MyAccessToken&gt;&amp;query=select+count(1)+from+&lt;MyTable&gt;&amp;useLegacySql=0
  </code></pre>
  
  <p>Entering the URL in the MATLAB error into a POST requester shows the following (generic) error, so it appears the URL is malformed:</p>
  
  <pre><code>{
      "error": {
          "errors": [
              {
                  "domain": "global",
                  "reason": "required",
                  "message": "Required parameter is missing"
              }
          ],
          "code": 400,
          "message": "Required parameter is missing"
      }
  }
  </code></pre>
  
  <p>How can I use MATLAB's webread to accomplish the same thing as the above curl request?</p>