{
  "schema_version": "1.0.0",
  "id": "unsubscribe-request-handler",
  "title": "Honour unsubscribe requests sent by email",
  "category": "email",
  "difficulty": "intermediate",
  "featured": false,
  "description": "When someone replies \"unsubscribe\" or \"remove me\", unsubscribe them in Mailchimp and confirm by reply, or say so when they were not on the list.",
  "tags": [
    "email",
    "mailchimp",
    "unsubscribe",
    "compliance",
    "gmail"
  ],
  "apps": [
    "Gmail",
    "Mailchimp",
    "Paths by Zapier"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 5 steps after the trigger",
      "Paths by Zapier"
    ]
  },
  "tasks": {
    "typical": 3,
    "max": 3
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Email Matching Search",
    "kind": "polling",
    "title": "New removal request",
    "why": "Catches the usual phrasings. It also matches emails that merely mention the word, which is why step 2 checks the list before acting.",
    "config": {
      "Search String": "(\"unsubscribe\" OR \"remove me\" OR \"stop emailing\" OR \"take me off\") -from:me newer_than:3d"
    },
    "outputs": [
      "message_id",
      "thread_id",
      "from_email",
      "from_name",
      "to",
      "subject",
      "date",
      "body_plain",
      "snippet",
      "labels",
      "attachment_count",
      "attachment_names"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "member",
      "kind": "search",
      "app": "Mailchimp",
      "event": "Find Subscriber",
      "title": "Look the sender up in the audience",
      "why": "Searches the newsletter audience by the sender address.",
      "fields": {
        "Audience": "YOUR_MAILCHIMP_AUDIENCE",
        "Subscriber Email": "{{trigger.from_email}}",
        "Should this step be considered a \"success\" when nothing is found?": "Yes"
      },
      "outputs": [
        "id",
        "status",
        "email_address",
        "_zap_search_was_found_status"
      ]
    },
    {
      "key": "route",
      "kind": "paths",
      "app": "Paths by Zapier",
      "event": "Split into paths",
      "title": "On the list or not",
      "why": "The rules test the search result both ways, so exactly one path runs.",
      "paths": [
        {
          "name": "Subscribed",
          "conditions": [
            [
              {
                "field": "{{member._zap_search_was_found_status}}",
                "operator": "(Boolean) Is true"
              }
            ]
          ],
          "usually": true,
          "steps": [
            {
              "key": "unsub",
              "kind": "action",
              "app": "Mailchimp",
              "event": "Add/Update Subscriber",
              "title": "Unsubscribe them",
              "why": "Sets the status to unsubscribed. Mailchimp keeps the record so they are not re-imported later.",
              "fields": {
                "Audience": "YOUR_MAILCHIMP_AUDIENCE",
                "Subscriber Email": "{{trigger.from_email}}",
                "Status": "Unsubscribed",
                "Update Existing": "Yes"
              },
              "outputs": [
                "id",
                "status"
              ]
            },
            {
              "key": "confirm",
              "kind": "action",
              "app": "Gmail",
              "event": "Reply to Email",
              "title": "Confirm by reply",
              "why": "A short reply in the same thread closes the loop.",
              "fields": {
                "Thread": "{{trigger.thread_id}}",
                "To": "{{trigger.from_email}}",
                "Body Type": "plain",
                "Body": "Hi {{trigger.from_name}},\n\nDone: {{trigger.from_email}} is unsubscribed from our newsletter and will not receive it again. Sorry for the noise.\n\nYOUR_BUSINESS_NAME"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        },
        {
          "name": "Not on the list",
          "conditions": [
            [
              {
                "field": "{{member._zap_search_was_found_status}}",
                "operator": "(Boolean) Is false"
              }
            ]
          ],
          "usually": false,
          "steps": [
            {
              "key": "explain",
              "kind": "action",
              "app": "Gmail",
              "event": "Reply to Email",
              "title": "Explain they are not on the list",
              "why": "Often the newsletter went to a different address. The reply asks which one.",
              "fields": {
                "Thread": "{{trigger.thread_id}}",
                "To": "{{trigger.from_email}}",
                "Body Type": "plain",
                "Body": "Hi {{trigger.from_name}},\n\nWe could not find {{trigger.from_email}} on our newsletter list. If the newsletter reaches you at another address, reply with it and we will remove that one.\n\nYOUR_BUSINESS_NAME"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        }
      ]
    }
  ]
}
