Skip to content

Conversation

vini-machado
Copy link

Description

When making API requests to Airtable, table names that contain a / (e.g., Subscriptions/Contracts) cause request failures because the / is interpreted as a path separator. The requests library does not automatically handle this, leading to an invalid URL.

Expected Behavior

  • The / in table names should be properly encoded as %2F, ensuring a valid API request.
  • Other parts of the URL (such as the base path) should remain unchanged.
  • The API should return the expected data instead of failing due to misinterpretation of / in the table name.

@vini-machado vini-machado changed the title Handling Table Names with / in Airtable API Requests Handling Table Names with / in Airtable API Requests Feb 10, 2025
message=error_json.get('message', json.dumps(response.json())))

error_json = response.json()
if isinstance(error_json, dict) and "error" in error_json:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -94,18 +95,29 @@ def __init__(self, base_id, api_key, dict_class=OrderedDict):
def __request(self, method, url, params=None, payload=None):
if method in ['POST', 'PUT', 'PATCH']:
self.headers.update({'Content-type': 'application/json'})

encoded_url = posixpath.join(self.base_url, urllib.parse.quote(url, safe=""))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't quote the whole url once you're here. Instead quote the table_name in the other functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants