Hmm, could you provide the script you've got so far? I'll see if I can help
May I also know how much JavaScript experience you have?
Hmm, could you provide the script you've got so far? I'll see if I can help
May I also know how much JavaScript experience you have?
Thank you. I have this so far:
// Airtable integration with PAT
const airtable = Airtable.configure({
apiKey: ScriptApp.getEnvironment().getVariable('AIRTABLE_PAT')
});
const table = airtable.base('appCf1sGZAwiIBU6k/tbleWwX6yxhZY8aHk').table('tbl3QwmZLBau3rK5P');
but Airtable.configure requires the library.
Experience? Not much. Enough to do small things with the help of ChatGPT and Bard. Sorry.
Thank you. I have this so far:
// Airtable integration with PAT
const airtable = Airtable.configure({
apiKey: ScriptApp.getEnvironment().getVariable('AIRTABLE_PAT')
});
const table = airtable.base('appCf1sGZAwiIBU6k/tbleWwX6yxhZY8aHk').table('tbl3QwmZLBau3rK5P');
but Airtable.configure requires the library.
Experience? Not much. Enough to do small things with the help of ChatGPT and Bard. Sorry.
Ah, no worries! You mentioned you weren't too sure how to use your PAT, so here's how I would set up my PAT so that you have a reference:

You'll just need to give it write permissions and select the base you want to send data into
Here's a script that will create new records in a base of your choice:
function main(){
var myHeaders = {
"Authorization": "Bearer YOUR_PAT_HERE",
"Content-Type": "application/json"
};
var raw = JSON.stringify({
"records": [
{
"fields": {
"Label": "Test1"
}
}
]
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
payload: raw
};
var response = UrlFetchApp.fetch("https://api.airtable.com/v0/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c/", requestOptions);
console.log(response.getContentText());
}
Just replace "YOUR_PAT_HERE" with your PAT, as well as update the URL in the fetch to be your base and table ID, specifically this bit:
https://api.airtable.com/v0/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c
You'd update it so that it was https://api.airtable.com/v0/YOUR_BASE_ID/YOUR_TABLE_ID
And you can get your base and table ID from going to the specific table you need, where the URL would be, for example:
https://airtable.com/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c/viwFuVZVRlLEUiCpL?blocks=bip4Em7XSFdFnv5yF
And the base ID would be: appz6YcyO3dXfqDWV
And the table ID would be: tblsCy38oC7N7FE4c
I realize that you probably already some if not most of this stuff, but figured I'd err on the side of oversharing in case it helped! Let me know if you could use more help and I'll see what I can do
Ah, no worries! You mentioned you weren't too sure how to use your PAT, so here's how I would set up my PAT so that you have a reference:

You'll just need to give it write permissions and select the base you want to send data into
Here's a script that will create new records in a base of your choice:
function main(){
var myHeaders = {
"Authorization": "Bearer YOUR_PAT_HERE",
"Content-Type": "application/json"
};
var raw = JSON.stringify({
"records": [
{
"fields": {
"Label": "Test1"
}
}
]
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
payload: raw
};
var response = UrlFetchApp.fetch("https://api.airtable.com/v0/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c/", requestOptions);
console.log(response.getContentText());
}
Just replace "YOUR_PAT_HERE" with your PAT, as well as update the URL in the fetch to be your base and table ID, specifically this bit:
https://api.airtable.com/v0/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c
You'd update it so that it was https://api.airtable.com/v0/YOUR_BASE_ID/YOUR_TABLE_ID
And you can get your base and table ID from going to the specific table you need, where the URL would be, for example:
https://airtable.com/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c/viwFuVZVRlLEUiCpL?blocks=bip4Em7XSFdFnv5yF
And the base ID would be: appz6YcyO3dXfqDWV
And the table ID would be: tblsCy38oC7N7FE4c
I realize that you probably already some if not most of this stuff, but figured I'd err on the side of oversharing in case it helped! Let me know if you could use more help and I'll see what I can do
Wow! This is awesome. It works perfectly. Thank you so much and thank you for your patience. Please, oversharing is ideal for me. 🙏
Wow! This is awesome. It works perfectly. Thank you so much and thank you for your patience. Please, oversharing is ideal for me. 🙏
Glad I could help!
Ah, no worries! You mentioned you weren't too sure how to use your PAT, so here's how I would set up my PAT so that you have a reference:

You'll just need to give it write permissions and select the base you want to send data into
Here's a script that will create new records in a base of your choice:
function main(){
var myHeaders = {
"Authorization": "Bearer YOUR_PAT_HERE",
"Content-Type": "application/json"
};
var raw = JSON.stringify({
"records": [
{
"fields": {
"Label": "Test1"
}
}
]
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
payload: raw
};
var response = UrlFetchApp.fetch("https://api.airtable.com/v0/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c/", requestOptions);
console.log(response.getContentText());
}
Just replace "YOUR_PAT_HERE" with your PAT, as well as update the URL in the fetch to be your base and table ID, specifically this bit:
https://api.airtable.com/v0/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c
You'd update it so that it was https://api.airtable.com/v0/YOUR_BASE_ID/YOUR_TABLE_ID
And you can get your base and table ID from going to the specific table you need, where the URL would be, for example:
https://airtable.com/appz6YcyO3dXfqDWV/tblsCy38oC7N7FE4c/viwFuVZVRlLEUiCpL?blocks=bip4Em7XSFdFnv5yF
And the base ID would be: appz6YcyO3dXfqDWV
And the table ID would be: tblsCy38oC7N7FE4c
I realize that you probably already some if not most of this stuff, but figured I'd err on the side of oversharing in case it helped! Let me know if you could use more help and I'll see what I can do
Hello !
First of all I want to say Thanks you by your efforts solving this issue. I'm having a similar problem trying to get data using google Apps Script from Airtable.
I've already created my PAT and I'm making a quite simple request. This is my code :
function requestAirtable(url, offset) {
const api_key= 'patJt0....RRL'
if(offset!== undefined){
url = url + '?offset=' + offset
}
var headers ={
'Authorization' : 'Bearer ' + api_key,
'Content-Type' : 'application/json'
}
var options={
headers : headers,
method : 'GET'
}
var response = UrlFetchApp.fetch(url,options).getContentText();
var result = JSON.parse(response)
//console.log('result: ',result.records)
return result
}
My problem is that I'm getting this error :
failed for https://api.airtable.com returned code 401. Truncated server response: {"error":{"type":"AUTHENTICATION_REQUIRED","message":"Authentication required"}}
Thanks you in advance!
Hello !
First of all I want to say Thanks you by your efforts solving this issue. I'm having a similar problem trying to get data using google Apps Script from Airtable.
I've already created my PAT and I'm making a quite simple request. This is my code :
function requestAirtable(url, offset) {
const api_key= 'patJt0....RRL'
if(offset!== undefined){
url = url + '?offset=' + offset
}
var headers ={
'Authorization' : 'Bearer ' + api_key,
'Content-Type' : 'application/json'
}
var options={
headers : headers,
method : 'GET'
}
var response = UrlFetchApp.fetch(url,options).getContentText();
var result = JSON.parse(response)
//console.log('result: ',result.records)
return result
}
My problem is that I'm getting this error :
failed for https://api.airtable.com returned code 401. Truncated server response: {"error":{"type":"AUTHENTICATION_REQUIRED","message":"Authentication required"}}
Thanks you in advance!
Hmm, your code looks fine actually. Just to confirm, you modified the "api_key" value so that it wasn't visible in this forum, right? FWIW, this works fine for me in Google Apps Script:
const api_key = 'YOUR_PAT_HERE'
const url = 'YOUR_URL_HERE'
function test(){
requestAirtable(url)
}
function requestAirtable(url, offset) {
if(offset!== undefined){
url = url + '?offset=' + offset
}
var headers ={
'Authorization' : 'Bearer ' + api_key,
'Content-Type' : 'application/json'
}
var options={
headers : headers,
method : 'GET'
}
var response = UrlFetchApp.fetch(url,options).getContentText();
var result = JSON.parse(response)
console.log('result: ',result.records)
return result
}
Hmm, your code looks fine actually. Just to confirm, you modified the "api_key" value so that it wasn't visible in this forum, right? FWIW, this works fine for me in Google Apps Script:
const api_key = 'YOUR_PAT_HERE'
const url = 'YOUR_URL_HERE'
function test(){
requestAirtable(url)
}
function requestAirtable(url, offset) {
if(offset!== undefined){
url = url + '?offset=' + offset
}
var headers ={
'Authorization' : 'Bearer ' + api_key,
'Content-Type' : 'application/json'
}
var options={
headers : headers,
method : 'GET'
}
var response = UrlFetchApp.fetch(url,options).getContentText();
var result = JSON.parse(response)
console.log('result: ',result.records)
return result
}
The code is working! I made a mistake when generating the token and just copied the first part (before the ".")... Thanks you very much for testing!
The code is working! I made a mistake when generating the token and just copied the first part (before the ".")... Thanks you very much for testing!
Nice! I'm glad you got it sorted!