Help

Unable to create table in exisiting base

Topic Labels: API Scripting
2083 4
cancel
Showing results for 
Search instead for 
Did you mean: 
sharim007
4 - Data Explorer
4 - Data Explorer

I am trying to create a table in an existing base using below endpoint but getting a not found error - 

'type': 'NOT_FOUND'
===============================================
table_name = "Members"
description = "Members"
fields = [
    {
        "name": "UserName",
        "type": "singleLineText"
    },
    {
        "name": "Name",
        "type": "singleLineText"
    }
]
 ================================
data = {
            "name": table_name,
            "description": description,
            "fields": fields
        }
 
headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json"
        }
response = requests.post(url, headers=headers, data=json.dumps(data))
4 Replies 4
LeotaMcDonald
4 - Data Explorer
4 - Data Explorer

Hy i can see your post and i have some suggestion

import requests
import json

api_key = "YOUR_AIRTABLE_API_KEY"
base_id = "YOUR_BASE_ID"

table_name = "Members"
description = "Members"
fields = [
{
"name": "UserName",
"type": "singleLineText"
},
{
"name": "Name",
"type": "singleLineText"
}
]

data = {
"name": table_name,
"description": description,
"fields": fields
}

url = f"https://api.airtable.com/v0/{base_id}/Members"

headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}

response = requests.post(url, headers=headers, data=json.dumps(data))

print(response.status_code)
print(response.json())

Please make sure to replace "YOUR_AIRTABLE_API_KEY" and "YOUR_BASE_ID" with your actual Airtable API key and base ID respectively. Also, ensure that your API key has the necessary permissions to create a table in the base.

Thanks and regads

LeotaMcDonald

LeotaMcDonald
4 - Data Explorer
4 - Data Explorer

Hy there thanks for sharing. 

 

import requests
import json

base_id = "YOUR_BASE_ID" # Replace this with the actual ID of your base
table_name = "Members"
description = "Members"
fields = [
{
"name": "UserName",
"type": "singleLineText"
},
{
"name": "Name",
"type": "singleLineText"
}
]

data = {
"name": table_name,
"description": description, TellHappyStar Survey

"fields": fields
}

api_key = "YOUR_API_KEY" # Replace this with your actual Airtable API key
url = f"https://api.airtable.com/v0/{base_id}/{table_name}"

headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}

response = requests.post(url, headers=headers, data=json.dumps(data))

print(response.json())

 

Thanks and regards

LeotaMcDonald

Maxineburns23
4 - Data Explorer
4 - Data Explorer

@sharim007 wrote:

I am trying to create a table in an existing base using below endpoint but getting a not found error - 

'type': 'NOT_FOUND'
===============================================
table_name = "Members"
description = "Members"
fields = [
    {
        "name": "UserName",
        "type": "singleLineText"
    },
    {
        "name": "Name",
        "type": "singleLineText"
    }
]
 ================================
data = {
            "name": table_name,
            "description": description,
            "fields": fields
        }
 
headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json"
        }
response = requests.post(url, headers=headers, data=json.dumps(data))

The error message "NOT_FOUND" typically indicates that the specified endpoint or resource was not found on the server. In the case of creating a table in an existing base using the Airtable API, the endpoint you are using is incorrect. The correct endpoint for creating a table in an existing base using the Airtable API is as follows.

https://api.airtable.com/v0/{base_id}/{table_name}

You should replace {base_id} with the actual ID of your base and {table_name} with the desired name for the new table. The base ID can be found in the Airtable API documentation or by logging into your Airtable account and inspecting the URL when viewing the base. Here's how the modified code should look like.

import requests
import json

base_id = "YOUR_BASE_ID"  # Replace with your actual base ID
table_name = "Members"
description = "Members"
fields = [
    {
        "name": "UserName",
        "type": "singleLineText"
    },
    {
        "name": "Name",
        "type": "singleLineText"
    }
]

url = f"https://api.airtable.com/v0/{base_id}/{table_name}"

data = {
    "fields": fields,
    "description": description
}

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers, data=json.dumps(data))

print(response.status_code)
print(response.json())

Make sure to replace "YOUR_BASE_ID" with the actual base ID you want to create the table in. Additionally, ensure that you have the necessary permissions and your API key is correct and authorized to perform the create action. Double-check the API key and verify that it has the appropriate permissions to access and modify your base. With these changes, the code should be able to create the new table in the specified existing base.

Daniellehale
4 - Data Explorer
4 - Data Explorer

You can verify your API request payload for any syntax errors or missing required fields. Review the Airtable API documentation to ensure you are using the correct structure and parameters when creating a new table.

Best regard,
livetheorangelife