Help

Re: Duplicate Base via new API

3457 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Joseph_Roza
8 - Airtable Astronomer
8 - Airtable Astronomer

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 =>

 

3 Replies 3

Hey @Joseph_Roza

This is a really good example of... just because you can do something, doesn't mean you should do something.
The idea of creating a button that duplicates an entire base seems to indicate that it's something you want to do rather frequently.

I'm curious to learn a bit more about your requirements and the use case that's pushing you to look into this functionality. Digging into what workflow you're trying to solve for and support will probably uncover a more sustainable and technically sound solution.

Any details here would be greatly appreciated.

Joseph_Roza
8 - Airtable Astronomer
8 - Airtable Astronomer

Thank you for responding @Ben_Young1 

The use case for this particular feature is for a more stream-lined approach to sharing a particular base with clients, especially customized bases. I have a sizable-enough client list that it would seem to be less-than-ideal to do this by the more classic method - share the base with them, and have them duplicate it. That just comes across as a little clunky, especially from a deliverability standpoint (as in, I need to be available to share the base with them, so they can duplicate it). In this case, they can log-in to their account dashboard, deliver whatever necessary information they need (API Key/token, base name etc.), push the button, and the base shows up in their account.

I had looked into this a while back, but this only appears to be do'able with the new API, but perhaps I'm misunderstanding. Anything else you might suggest? I really appreciate any insight you might be willing to offer.

I don't suppose you had any additional thoughts on this, or is it something of a lost cause?