UPDATE
This comprehensive answer resolved my issue:
https://stackoverflow.com/a/29112224/1045794
I am looking at https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart_code.htm
After getting the Salesforce Version, I am try trying to get a list of resources.
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.
var url = 'https://company.lightning.force.com/services/data/v51.0/';
var myBody = '';
var headers = {"Authorization" : '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)
Edit - I know the URL is correct because testing https://company.lightning.force.com/services/data/ does return the version numbers
Edit 2 - Changing URL to https://company.my.salesforce.com/services/data/v50.0/ results in the same error