- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎May 24, 2023 05:21 AM - edited ‎May 24, 2023 06:57 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Aug 17, 2023 03:58 AM - edited ‎Aug 17, 2023 03:59 AM
@saadat, Airtable's JavaScript environment doesn't support the Utilities.base64Encode() method, which is why the solution relies on a custom function, btoa(), to encode.

- « Previous
-
- 1
- 2
- Next »