Question

Missing data after status response 200 in Code by Zapier

  • 12 September 2023
  • 1 reply
  • 107 views

Hello everyone,

 I’m having an error everytime I’ve run a custom code into Code by Zapier. The main idea is to have a personalized “Welcome” greetings with a custom related form “Link” embbeded into this welcome text in order to be sent to the Customer. The issue shows up when I’m requesting through Airtable Web API the record with the “Link” related. The response status request is 200 which is OK. Also in Visual Studio Code the answer and the data is OK too.

BUT when I run the code into Code by Zapier, the mentioned “Link” is missing.

Does anyone have experienced something like this?

import requests
import json

input_data = {
'api_key':'',
'base_form':'theBaseWithTheTable',
'program':'theProgramName',
'client_name':'Customer',
'table_form':'theTableWithTheLink'
}

API_KEY = input_data['api_key']

base_id = ''
table_id = ''
client_name = input_data['client_name']
link = ''

url = f'https://api.airtable.com/v0/meta/bases'

headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type':f'application/json',
}
# get base by program name
response = requests.get(url, headers=headers)

if response.status_code == 200:
data = response.json()
for base in data['bases']:
for k, v in base.items():
if input_data['base_form'] in v:
base_id = base.get('id')

url = f'https://api.airtable.com/v0/meta/bases/{base_id}/tables'
# get table by base
response = requests.get(url, headers=headers)

if response.status_code == 200:
data = response.json()
for table in data['tables']:
for k, v in table.items():
if input_data['table_form'] in v:
table_id = table.get('id')

url = f'https://api.airtable.com/v0/{base_id}/{table_id}'

# find the link into the table
response = requests.get(url, headers=headers)

if response.status_code == 200:
data = response.json()
for row in data['records']:
fields = row.get('fields')
for k, v in fields.items():
if input_data['program'] in v:
link = fields.get('Link')


welcome = f'<h1>¡Welcome {client_name}</h1>\
<p>Complete the following form:</p>\
<a href="{link}">Your Form</a>\

output = {'welcome':welcome,'link':link}

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 7
Badge +14

Hi @Agus 

Good question.

Have you tried using Python logging to help you see which Record IDs are being returned to then make sure those Airtable Record IDs have values for the Link field?

Have you tried using ChatGPT to help with the Python Code?