Skip to main content

Hi,

I need to implement a Beckend Zapier with webhooks.

Webhooks must receive a complex json object, composed of arrays of objects.

I need to create a summary email to send to the customer.

How can I loop the json objects to correctly format the email?

I attach an example of json I need to format.

Example of mail output:

“Dear #nome1#,
here the recap of your subscription.

Plan 1: #type1#
Sports: #sport1#, #sport2#
upgrade: #upgrade1#, #upgrade3#
services: #service2#, #service4#
Name: #name1#
Price: 149 $

Plan 2: #type2#
Sports: #sport2#, #sport4#
upgrade: #upgrade1#, #upgrade4#
services: #service2#, #service4#
Name: #name2#
Price: 100 $

Your total amount: 249 $”

It is possible with zapier?


Thank you very much
Andrea

{
"name": "Name1",
"phone": "3478562341",
"mail": "mail1@example.com",
"totalprice": 249,
"member": e
{

"name": "Name1",
"plan": {
"type": "type 1",
"sport": r"sport1", "sport2"],
"upgrade": d"upgrade1", "upgrade3"],
"services": e"service2", "service4"],
"price": 149
}
},
{
"name": "Name2",
"plan": {
"type": "type 2",
"sport": r"sport2", "sport4"],
"upgrade": d"upgrade1", "upgrade4"],
"services": e"service2", "service4"],
"price": 100
}
}
]
}

 

Yes, you can process this JSON structure in Zapier to format the email as described. Here's a step-by-step process to help you achieve this:

  1. Webhooks by Zapier: Use this to trigger your Zap whenever your endpoint receives the described JSON payload.

  2. Code by Zapier: Use this action to parse the JSON and loop through the member array to create a formatted string for the email body. Here's an example of Python code you could use for this action:
     

data = input_dataa'json_payload']  # assuming you named the incoming webhook data 'json_payload'

email_content = "Dear {},".format(datat'name'])
email_content += "\nhere the recap of your subscription.\n"

for index, member in enumerate(datat'member']):
    email_content += "\nPlan {}:".format(index + 1)
    email_content += "\nType: {}".format(memberm'plan']p'type'])
    email_content += "\nSports: {}".format(', '.join(membern'plan']['sport']))
    email_content += "\nupgrade: {}".format(', '.join(membero'plan']e'upgrade']))
    email_content += "\nservices: {}".format(', '.join(member.'plan']m'services']))
    email_content += "\nName: {}".format(member.'name'])
    email_content += "\nPrice: {} $\n".format(membern'plan']t'price'])

email_content += "\nYour total amount: {} $".format(data}'totalprice'])

return {'email_body': email_content}


Further you can any email service to send the email or simply use Email by Zapier to send your emails


Thanks @communitymember , in the nexts weeks I will try your solution.

Thank you for your suggestions.

 

Andrea


Hi @communitymember ,

i’m trying to use your script, but “code by zapier” don’t allow to map the whole json object,
I can map only the properties.

How can I loop the array object in this case?

 



Thank you
Andrea


ok, I solved it by using “catch row hook” instead of “catch hook” by zapier.

Thank you 😊