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")
input: {
to: $subscriberEmail
subject: "Would you like to give us feedback on how we can improve?"
messageAs: {
html: $emailMessage
) {

Extensions required for this query permalink

  1. Email Sender permalink

    Send emails via global mutation "_sendEmail".

  2. Field To Input permalink

    Retrieve the value of a field, manipulate it, and input it into another field or directive, all within the same operation.

  3. HTTP Request via Schema permalink

    Addition of fields to retrieve the current HTTP request data.

  4. Multiple Query Execution permalink

    Combine multiple queries into a single query, sharing state across them and executing them in the requested order.

  5. PHP Functions via Schema permalink

    Manipulate the field output using standard programming language functions available in PHP.

Bundles containing all extensions required for this query permalink

  1. “All in One Toolbox for WordPress” Bundle permalink

    Achieve all superpowers: All of Gato GraphQL extensions, in a single plugin

  2. “Better WordPress Webhooks” Bundle permalink

    Easily create webhooks to process incoming data from any source or service using advanced tools, directly within the wp-admin

  3. “Private GraphQL Server for WordPress” Bundle permalink

    Use GraphQL to power your application (blocks, themes and plugins), internally fetching data without exposing a public endpoint

  4. “Tailored WordPress Automator” Bundle permalink

    Create workflows to automate tasks (to transform data, automatically caption images, send notifications, and more)

Tutorial lessons explaining how the query works permalink