Why isn't retrieving an Airtable cell via an identifier working in Python?

Using Flask with the Airtable API, fetching a specific cell by its unique id fails while retrieving all data succeeds. What could be the problem?

from flask import Flask, request, render_template
import requests

app = Flask(__name__)

@app.route('/fetch')
def fetch_record():
    unique_id = request.args.get('uid')
    api_endpoint = f"https://api.airtable.com/v0/YourBase/YourTable/{unique_id}"
    headers = {"Authorization": "Bearer YOUR_TOKEN"}
    response = requests.get(api_endpoint, headers=headers)
    record = response.json().get('fields', {}).get('uid', 'Not Found')
    return render_template('result.html', record=record)

if __name__ == '__main__':
    app.run(debug=True)

hey, maybe ur problem is a mismatched field name. the record might not even have a ‘uid’ field. check if your endpoint returns the intended id and adjust accordingly. good luck!

In my experience, these problems usually arise from an incorrect mapping between the record identifier and the field names returned. I once encountered a similar situation where the record’s unique id was not what I expected, and I overlooked the structure of the JSON response. Here, rather than assuming the ‘uid’ field is present in the record’s fields, it might be nested differently or named otherwise. I recommend verifying the response structure with some debug prints to better understand how Airtable is returning the data, which often reveals the mismatch.