Skip to main content

I'm trying to create a zap that uses Zapier Tables in conjunction with with a "Run Python in Code by Zapier" action.

The zap is not triggered by Tables, it’s triggered by something else, but the code in the Python action needs to read multiple rows from the table. (The idea is to make it easier to tweak some of the configuration of the zap by editing the table, rather than needing to modify the code.)  

To do this, I created a “Find Records (Output as Line Items) in Zapier Tables” action before the Python action. The Tables action looks up rows based on data from the zap’s trigger, and seems to be finding the correct data.

The trouble is in getting this data to the Python code. Right now I have one of the “Input Data” fields in the Python action set to “Data” from the Tables action. The Python code then accesses it like this:
 

table_data = input_data.get('table_data', _])

I was hoping this would be either a list of objects, dicts, or even lists, or perhaps JSON. Instead it’s a single string containing the data formatted like this:

created_at: 2023-07-17T18:12:48.231000+00:00
data: {'f1': 'foo-bar', 'f2': 'howdy, folks.'}
edited_at: 2023-07-17T18:13:03.226760+00:00
errors: {}
id: 01H5JGW4F7ZFJMC1TNYYZNMYDA
schema_revision_id: 5

created_at: 2023-07-17T18:01:11.883000+00:00
data: {'f1': 'foo-bar', 'f2': 'hello, world!'}
edited_at: 2023-07-17T18:03:51.262171+00:00
errors: {}
id: 01H5JG6WEB9S557JRZHPKN3B36
schema_revision_id: 2

What format is this? This isn’t JSON or YAML, and I can’t find any documentation explaining what this is.

Is there a way I can get the table data (either the entire table or a subset consisting of multiple rows would be fine) in Python as a real data structure and not a flattened string?

Hi @xenomachina 

Good question.

Zap steps automatically parse JSON data to create variables, which probably is why you are seeing the data in the current format.

There’s a trick to get the underlying JSON data.

Use an empty Webhook - POST action to send the data to another Zap that has the trigger Webhook - Catch Hook.


Hi Troy,

Thanks for your reply.

 

Zap steps automatically parse JSON data to create variables, which probably is why you are seeing the data in the current format.

What is that format, though? It seems to be line-based, with fields separated by newlines, and then a double-newline between each table row. The field lines are then in the format “name: value”, where value is not JSON. I think it’s maybe using Python’s repr to write these values, which is an odd choice. (repr’s output isn’t reliably deserializable the way JSON is.)

 

There’s a trick to get the underlying JSON data.

Use an empty Webhook - POST action to send the data to another Zap that has the trigger Webhook - Catch Hook.

Thanks for the suggestion, but that sounds way more complicated than it should be. I wanted to avoid having to parse the string, but even that is a lot simpler than having to split every zap that needs to access a table into two zaps. I already have five zaps using this same code, and I really don’t want to turn that into ten. (I’m actually also trying to find a way to condense them down to a single zap.)


@xenomachina 

Can you post screenshots with how the data is returned from the Zapier Tables step?


@xenomachina

Can you post screenshots with how the data is returned from the Zapier Tables step?

Sure:

I’m mapping “Data” from that action to the key “table_data” in Python:

And here’s the Python code to read it:

table_data = input_data.get('table_data')

table_data ends up being equal to:

"created_at: 2023-07-17T22:30:02.524000+00:00\ndata: {'f1': 'foo-bar', 'f2': 'hello, world!'}\nedited_at: 2023-07-17T22:30:16.747954+00:00\nerrors: {}\nid: 01H5JZK50W6G8HDJ280H68B98V\nschema_revision_id: 5\n\ncreated_at: 2023-07-17T18:12:48.231000+00:00\ndata: {'f1': 'foo-bar', 'f2': 'howdy, folks.'}\nedited_at: 2023-07-17T22:30:18.750945+00:00\nerrors: {}\nid: 01H5JGW4F7ZFJMC1TNYYZNMYDA\nschema_revision_id: 5"

Or if I print it (easier to read):

created_at: 2023-07-17T22:30:02.524000+00:00
data: {'f1': 'foo-bar', 'f2': 'hello, world!'}
edited_at: 2023-07-17T22:30:16.747954+00:00
errors: {}
id: 01H5JZK50W6G8HDJ280H68B98V
schema_revision_id: 5

created_at: 2023-07-17T18:12:48.231000+00:00
data: {'f1': 'foo-bar', 'f2': 'howdy, folks.'}
edited_at: 2023-07-17T22:30:18.750945+00:00
errors: {}
id: 01H5JGW4F7ZFJMC1TNYYZNMYDA
schema_revision_id: 5

 


@xenomachina 

I was able to replicate how the data is shown as a structured string in the Code step.

 

Each of the fields from Zapier Tables will be it’s own variable (as an array) that you can map into the Code step.

 

You can submit feedback to the Zapier Tables team here: https://eap.zapier.app/


 

Each of the fields from Zapier Tables will be it’s own variable (as an array) that you can map into the Code step.

 

 

How?

 

The options I see for mapping the data I need into Python from the Tables action are:

1. Data, which looks like this:

and despite saying “No data” in the mapping grid, contains the string I’ve been talking about in this post with all of the data from the table (including metadata), but in an odd format.

 

2. A column. The column I need is called “regex”, and looks like:

this value is not an array, but is instead a single string with all of the column’s values concatenated together with commas in between. In this example, I get “hello, world!,howdy, folks.”. Because it’s a single string, I can’t tell the difference between the row separator and a literal comma in the data.

 

Some more info, in case it matters: in my Tables action is a “Find Records (Output as Line Items) in Zapier Tables” action. I see there’s also a “Find or Create Record” option, but it looks like that only returns one record, while I need a list of records.


@xenomachina 

Looks like the your current option would be to use the Data variable.

You’d have to configure Code to parse and prep the data. (e.g. isolate all of the “data” values)

 

Alternatively, you can try asking AI.

Zap action: ChatGPT - Extract Structured Data

 

If you need help with the custom Code, consider hiring a Certified Zapier Expert: https://zapier.com/experts/automation-ace


I’ve already written the code to parse it, it’s just that this is code that seems like it shouldn’t have to be written in the first place.

That is, why is Zapier cramming the table data into a string instead of passing structured data? And if it must pass use a string, why not use JSON or something else that’s designed for parsing, instead of an ad hoc format?

Frankly, this seems like a bug, or at the very least an omission, in the way Zapier Tables and Code by Zapier interoperate.


@xenomachina 

You can submit feedback to the Zapier Tables team here: https://eap.zapier.app/