title: Google Docs API in Google Apps Script as an external API (NOT as extended service)
body: <p>I am trying to use the new Google Docs API using Google Apps Script. Since new API is not yet available as an extended service, I am trying to do it using UrlFetchApp() but failing.</p>
  
  <p>Apologies for my naive attempt here:</p>
  
  <pre><code>function apiCall(){
  
  var API_KEY = 'YOUR_API_KEY';
  var username = 'YOUR_USERNAME';
  var password = 'YOU_PASSWORD';
  
  var DOC_ID = 'YOUR_DOC_ID';
  var root = 'https://docs.googleapis.com/v1/documents/';
  var endpoint = DOC_ID;
  var query = '?key=' + API_KEY;
  
  var params = {
   'method': 'GET',
   'muteHttpExceptions': true,
   'headers': {
      'Authorization': 'Basic ' + Utilities.base64Encode(username + ':' +      password)
    }
  };
  
  var response = UrlFetchApp.fetch(root + endpoint + query, params);
  var data = response.getContentText();
  var json = JSON.parse(data);
  
  Logger.log(json);
  }
  </code></pre>
  
  <p>I get the following response:</p>
  
  <p><code>{error={code=401, message=Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or another valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project., status=UNAUTHENTICATED}}</code></p>
  
  <p>Can someone point to the right direction, where I can find some documentation how to use Google Docs API in Google Apps Script.</p>