[Off Topic] How to loop the Airtable and API data?

airtable = Airtable(AIRTABLE_BASE_ID, AIRTABLE_TABLE_NAME, AIRTABLE_API_KEY)

api_endpoint = ‘xxx’
json_data = requests.get(api_endpoint).json()
cryptodata = json_data[‘data’]

records = airtable.get_all(maxRecords=1000)

for r in records:
for currency in cryptodata:
if (r[‘fields’][‘name’] == currency[‘name’]):
#print(r[‘fields’][‘name’])
records = airtable.update_by_field(‘name’, currency[‘name’], {‘price’: currency[‘metrics’][‘market_data’][‘price_usd’]})
Hello, I’m a newbie to Python. When the API transmits data to Airtable, the preceding code is meant to update the data in Airtable.

Question:

How can it only UPDATE if a name already exists?

If there is no existing name, how can it ADD ONLY?

This is the code I use to see if any are already in use:
for r in records:
for currency in cryptodata:
if (r[‘fields’][‘name’] == currency[‘name’])

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.