Mechanic Get Mechanic
Task library

Automatically send account invite to new customers

This task sends account invitations to newly-created customers, whether created/imported through the Shopify admin or through another app. It does not send invitation emails for customers without an email address, or to customers who've signed up via your online store.

Try this task

When it runs

Occurs whenever a customer is created, with a 1 minute delay

What you choose

  • Invitation email subject
  • Invitation email body

Documentation

This task sends account invitations to newly-created customers, whether created/imported through the Shopify admin or through another app. It does not send invitation emails for customers without an email address, or to customers who've signed up via your online store.

(Wondering about the 1-minute delay? It's because customers who sign themselves up aren't marked as such until a few seconds after their account is created. So, Mechanic waits a minute, just to be sure.)

Task code and subscriptions

You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.

Subscriptions

shopify/customers/create+1.minute
How task subscriptions work

Option types and flags

Task code

{% assign invitation_email_subject = options.invitation_email_subject__required %}
{% assign invitation_email_body = options.invitation_email_body__multiline_required %}

{% if event.topic == "shopify/customers/create" %}
  {% comment %}
    -- get customer data
  {% endcomment %}

  {% capture query %}
    query {
      customer(id: {{ customer.admin_graphql_api_id | json }}) {
        id
        displayName
        defaultEmailAddress {
          emailAddress
        }
        state
        tags
      }
    }
  {% endcapture %}

  {% assign result = query | shopify %}

  {% if event.preview %}
    {% capture result_json %}
      {
        "data": {
          "customer": {
            "id": "gid://shopify/Customer/1234567890",
            "state": "DISABLED"
          }
        }
      }
    {% endcapture %}

    {% assign result = result_json | parse_json %}
  {% endif %}

  {% assign customer = result.data.customer %}

  {% unless event.preview %}
    {% log customer: customer %}
  {% endunless %}

  {% unless customer.state == "DISABLED" %}
    {% log "Customer state is not 'DISABLED', so an account invite will not be sent." %}
    {% break %}
  {% endunless %}

  {% action "shopify" %}
    mutation {
      customerSendAccountInviteEmail(
        customerId: {{ customer.id | json }}
        email: {
          subject: {{ invitation_email_subject | json }}
          customMessage: {{ invitation_email_body | json }}
        }
      ) {
        customer {
          id
          displayName
          defaultEmailAddress {
            emailAddress
          }
          state
        }
      }
    }
  {% endaction %}
{% endif %}
Mechanic Liquid reference