Queries LibrarySend a farewell email to users who unsubscribe from ConvertKit (via a webhook)
Send a farewell email to users who unsubscribe from ConvertKit (via a webhook)
When a user triggers an event on ConvertKit (such as subscribing or unsubscribing), the service will call a webhook passing event data. We can set-up a Persisted Query as a webhook that processes this incoming data, and executes an action with it.
This query sends a farewell email (which includes a link to a form asking for feedback) to the person who unsubscribed on ConvertKit.
query ExtractPayloadData {
body: _httpRequestBody
bodyJSONObject: _strDecodeJSONObject(string: $__body)
subscriberFirstName: _objectProperty(
object: $__bodyJSONObject,
by: { path: "subscriber.first_name" }
)
@export(as: "subscriberFirstName")
subscriberEmail: _objectProperty(
object: $__bodyJSONObject,
by: { path: "subscriber.email_address" }
)
@export(as: "subscriberEmail")
}
query CreateEmailMessage(
$formURL: URL!
)
@depends(on: "ExtractPayloadData")
{
emailMessageTemplate: _strConvertMarkdownToHTML(
text: """
Hey {$subscriberFirstName}, it's sad to let you go!
Please be welcome to complete [this form]({$formURL}) and let us know if there is anything we can do better.
Thanks. Hope to see you back!
"""
)
emailMessage: _strReplaceMultiple(
search: ["{$subscriberFirstName}", "{$formURL}"],
replaceWith: [$subscriberFirstName, $formURL],
in: $__emailMessageTemplate
)
@export(as: "emailMessage")
}
mutation SendFarewellEmailToUnsubscribingUsersFromConvertKit
@depends(on: "CreateEmailMessage")
{
_sendEmail(
input: {
to: $subscriberEmail
subject: "Would you like to give us feedback on how we can improve?"
messageAs: {
html: $emailMessage
}
}
) {
status
}
}