Doug Christensen
Doug Christensen

Reputation: 23

Want to trigger a Zapier action for each email extracted from a list of emails using Python

I have a string variable in Zapier that contains multiple emails ([email protected],[email protected], etc.). I need to extract each email and pass it on to the next Zapier action.I've taken a screen shot of where this appears in Zapier So a string that has 2 emails would cause the next Zapier action to run twice.

I've tried parsing the string and loading a dictionary, returning the dictionary.

emails = []
attendeeList = input_data['attendeeEmails'].split()
for email in attendeeList:
    a = {'Email' : email}
    emails.append(a)
return emails

This returns all the emails in a form basically the same as they were submitted - comma separated list or string. (So not multiples). It does cause the next action to run in the Zap, but with multiple emails in the field "Email". Not what I want.

I've also tried just returning each email as I march through the created List.

attendeeList = input_data['attendeeEmails'].split()
for email in attendeeList:
    output = {'Email' : email}

I haven't seen any output from this one yet. It's taking me about 1/2 hr to see results from any tweaks.

I'm afraid I don't know Python very well - only what I could learn from several hours spent in "Code Academy". So I know enough to be dangerous. But with the passing of variables and purported ability of Zapier to trigger multiple actions from the return of one dictionary, I'm a little overwhelmed. I'm sure it's simple if you know more than me.

My source of the string containing the emails is Google Calendar. And with the 15 min checking cycle it's a long slog to get feedback on what I've done. Any guidance would be awesome.

Upvotes: 2

Views: 965

Answers (2)

Kieran
Kieran

Reputation: 3995

The following one-liner would give you a list of dictionaries from the comma-separated list of emails. Hopefully Zapier would take it from there.

[{'Email': email.strip()} for email in input_data['attendeeEmails'].split(',')]

Also please be aware you shouldn't have to wait 15 minutes every time. You can just click on re-test when you get to the 'test this step' stage.

Upvotes: 1

wpercy
wpercy

Reputation: 10090

You need to split on a delimiter, in this case a comma.

So your attendeeList would look like this:

attendeeList = input_data['attendeeEmails'].split(',')

And to remove any extra whitespace, you should then .strip() the emails in your loop like this:

for email in attendeeList:
    a = {'Email' : email.strip()}
    emails.append(a)

Upvotes: 0

Related Questions