title: Initiating Salesforce API in Google App Script
body: <p><strong>UPDATE</strong></p>
  <p>This comprehensive answer resolved my issue:</p>
  <p><a href="https://stackoverflow.com/a/29112224/1045794">https://stackoverflow.com/a/29112224/1045794</a></p>
  <hr>
  <p>I am looking at <a href="https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart_code.htm" rel="nofollow noreferrer">https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart_code.htm</a></p>
  <p>After getting the Salesforce Version, I am try trying to get a list of resources.</p>
  <p>This is the normal way I would access a 3rd party API, but is resulting in a 401 error as if I am unauthorised. I believe I am using the correct token but perhaps this is actually a bad request.</p>
  <pre><code>var url = 'https://company.lightning.force.com/services/data/v51.0/';
  
  var myBody = '';
  var headers = {&quot;Authorization&quot; : 'Bearer ' + 'my_token'};
  
  var params = {
     'method': 'GET',
     //'muteHttpExceptions': true,
     'headers': headers,
     'contentType': 'application/json',
     //'payload': myBody
  };
  
  var res = UrlFetchApp.fetch(url, params);
  
  var myObj = JSON.parse(res.getContentText());
  
  Logger.log(myObj)
  </code></pre>
  <p>Edit - I know the URL is correct because testing <a href="https://company.lightning.force.com/services/data/" rel="nofollow noreferrer">https://company.lightning.force.com/services/data/</a> does return the version numbers</p>
  <p>Edit 2 - Changing URL to <a href="https://company.my.salesforce.com/services/data/v50.0/" rel="nofollow noreferrer">https://company.my.salesforce.com/services/data/v50.0/</a> results in the same error</p>