Solved

How to send notification mail to a specific user's email from the server side through the API?

  • 24 November 2023
  • 5 replies
  • 105 views

Badge

I have a use case where  I want to send an email with placeholders to a single user, like a notification email. For example, when a user’s subscription is about to end, I want to send a reminder email only to that one user whose subscription is about to end from the server side.
Is there a way to manually trigger the flow from the server side using API by passing recipient’s email or profile Id and notification content as placeholders.
I looked for all the APIs klaviyo-api npm package provided, but couldn’t find any API suitable for my use case.
Please help me with this. Thank you

icon

Best answer by saulblum 27 November 2023, 22:03

View original

5 replies

Userlevel 5
Badge +7

You’d want to use the Create Event call to send a custom event to just one profile (assuming you also have a flow triggered off that event). All of the SDKs support this method. Include in the event properties any custom properties you’d want to include in the flow’s email.

Badge

Thank you so much for the answer.

I followed this and was able to send a notification email but I faced two issues.
1. The custom properties I added while creating the event are not reflected in the email or I am not finding a right way to add the properties in email template. 
 

 const createEventInput = {
data: {
type: 'event',
attributes: {
// the below properties are not showing up in the email.
properties: {
notification_title: 'This is notification title',
notification_content: 'This is notification content.',
content: 'hi, this is content'
},
metric: {
data: {
type: 'metric',
attributes: {
name: 'Web notification'
}
}
},
profile: {
data: {
type: 'profile',
attributes: {
email: 'sample@example.com'
}
}
}
}
}
}
  1. The email is being sent only once per profile, but my use case is to trigger the flow as many times the user triggers the event ! 
     

Please help me with the answers. Thank you.

Badge

thanks for the answer. 
When I follow this approach, I am facing two issues: 
1. The flow will be triggered only once for one profile, but I need to send the notification mail each time when I Create Event for a profile. 
2. The custom properties are not showing up in the mail which are set while creating a event.

Userlevel 5
Badge +7

Metric-triggered flows will fire for a profile each time the profile gets that event, unless you have a trigger filter that excludes certain instances of that event. (Segment flows can only be entered once per profile.)

Are you using the {{ event.property }} syntax to embed event properties in emails?

Badge

Thank you so much, yes metric-triggered flows will fire for a profile each time the profile gets that event. The smart sending feature was on because of that while testing for a single profile the email was not being sent multiple times.

also {{ event.property }} syntax worked perfectly.✌🏽🙌

Reply