Skip to main content

Hello!

I’m having trouble trying to include an input data variable to my JSON string using Python - Requests.

  • Trigger: Catch’s hook from a web form
  • Action: Consumes API to send a Confirmation email

Input Data

These are the fields the Zap retrieves from the webhook

 

Code (Action that sends de confirmation email):

import requests

url = "https://api.trx.icommarketing.com/email"

payload="{ \r\n \"From\": \"Icomm Test demo@demo.com\", \r\n \"To\": \"lucas.vargas@icommkt.com\", \r\n \"Cc\": \"\", \r\n \"Bcc\": \"\", \r\n \"Subject\": \"Hello :)\", \r\n \"Tag\": \"string\", \r\n \"HtmlBody\": \"Cuerpo del correo\", \r\n \"TextBody\": \"Texto plano\", \r\n \"ReplyTo\": \"daniel.alarcon@icommkt.com\", \r\n \"Headers\": s], \r\n \"TrackOpens\": true, \r\n \"TrackLinks\": \"HtmlAndText\", \r\n \"Attachments\": s \r\n { \r\n \"Name\": \"readme.txt\", \r\n \"Content\": \"dGVzdCBjb250ZW50\", \r\n \"ContentType\": \"text/plain\" }, \r\n { \r\n \"Name\": \"report.pdf\", \r\n \"Content\": \"dGVzdCBjb250ZW50\", \r\n \"ContentType\": \"application/octet-stream\" \r\n } \r\n ]\r\n }"
headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
'X-Trx-Api-Key': 'PRIVATE KEY'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

When I test the API it works because it sends an email "To\": \"lucas.vargas@icommkt.com\"

However, I want the email to be sent to the person who filled the form using “email” as a dynamic variable.

 

Hope someone can help me with this case

 

Regards

 

Hi @LucasIcomm 

There may be more elegant ways to do this but the simplest way would just be to include the email variable in the payload you’ve defined

 

payload="{  \r\n    \"From\": \"Icomm Test demo@demo.com\",  \r\n    \"To\": \""+input_datad'email']+"\",  \r\n    \"Cc\": \"\",  \r\n    \"Bcc\": \"\",  \r\n    \"Subject\": \"Hello :)\",  \r\n    \"Tag\": \"string\",  \r\n    \"HtmlBody\": \"Cuerpo del correo\",  \r\n    \"TextBody\": \"Texto plano\",  \r\n    \"ReplyTo\": \"daniel.alarcon@icommkt.com\",  \r\n    \"Headers\": \],  \r\n    \"TrackOpens\": true,  \r\n    \"TrackLinks\": \"HtmlAndText\",  \r\n    \"Attachments\": \    \r\n    {      \r\n        \"Name\": \"readme.txt\",      \r\n        \"Content\": \"dGVzdCBjb250ZW50\",      \r\n        \"ContentType\": \"text/plain\"    },    \r\n    {      \r\n        \"Name\": \"report.pdf\",      \r\n        \"Content\": \"dGVzdCBjb250ZW50\",      \r\n        \"ContentType\": \"application/octet-stream\"    \r\n    }  \r\n    ]\r\n    }"

 


Thank you GetUwired. This code worked perfectly.

 

I appreciate your help

 

Have a very nice day