I can't seem to get a valid access token in Airtable based on JavaScript code that works in a Google Apps Script. Here is the working code:
var clientId = '...';
var clientSecret = '...';
var url = 'https://accounts.spotify.com/api/token';
var headers = {
'Authorization': 'Basic ' + Utilities.base64Encode(clientId + ':' + clientSecret)
};
var payload = {
'grant_type': 'client_credentials'
};
var options = {
'method': 'post',
'headers': headers,
'payload': payload
};
var response = UrlFetchApp.fetch(url, options);
var accessToken = JSON.parse(response.getContentText()).access_token;
This code relies on objects and methods that don't exist in Airtable's automation coding environment, namely Utilities.base64encode() and UrlFetchApp.fetch(), so I have tried rewriting the script to work in Airtable. To bypass an encoding method, I simply encoded the clientId and clientSecret manually and substituted the encoded string for Utilities.base64encode(clientId + ':' + clientSecret). In order to fetch the access token, I have tried a few lines of declaring variables. This is what the Airtable script looks like:
var url = 'https://accounts.spotify.com/api/token';
var headers = {
'Authorization': 'Basic ' + '...'}; // '...' is the encoded string
var payload = {
'grant_type': 'client_credentials'};
var options = {
'method': 'post',
'headers': headers,
'payload': payload};
var responseToken = await fetch(url, options);
var dataToken = await responseToken;
var accessToken = await responseToken.access_token;
Have I approached this incorrectly? I appreciate any help.