Admittedly, I'm super new APIs in general, and I'm using ChatGPT to generate the code. So, if you're looking at it and you're like 'you and chatbot are wrong about everything and this can't be done', please let me know.
Here is my use case:
Imagine I am a duplicating a base and all of its tables and records from one Airtable account to another via API. I push a button, and it runs a script which performs this action.
My first question is, with the new API, is this even possible?
If so, my follow up question would be related to the code ChatGPT gave me. I filled out the placeholders with the appropriate information (I think), but I get a 404 error that returns 'Error Copying Base: undefined'.
I'm using the new token api with all scopes allowed on the particular base I'm trying to copy to another Airtable account.
My main question would be: what the heck am I doing wrong?
And also: is the SOURCE BASE ID and YOUR APP ID not the same thing? They're both just app ids for the base, yeah?
<script>
// Grab the button element by its ID
const copyButton = document.getElementById("copy-button");
// Add an event listener to the button to listen for clicks
copyButton.addEventListener("click", function() {
// Set the variables for the source and destination base IDs
var sourceBaseID = "YOUR_SOURCE_BASE_ID";
var destinationBaseID = "CLIENT_DESTINATION_BASE_ID";
// Set the variables for the Airtable API key and endpoint URL
var apiKey = "YOUR_API_KEY";
var endpoint = "https://api.airtable.com/v0/appYOUR_APP_ID/bases/" + sourceBaseID + "/duplicate";
// Create an options object for the fetch call
var options = {
method: "POST",
headers: {
"Authorization": "Bearer " + apiKey,
"Content-type": "application/json"
},
body: JSON.stringify({
"destination_base_id": destinationBaseID
})
};
// Make the fetch call to the Airtable API
fetch(endpoint, options)
.then(response =>