Send account invites to all customers in bulk, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Send account invites to all customers in bulk

Use this task to send out account invitations to all the customers you already have on file, with the push of a button. Optionally, filter by customer tag.

Runs Occurs when a user manually triggers the task and Occurs when a bulk operation is completed. Configuration includes only invite customers with this tag, invitation email subject, and invitation email body.

15-day free trial – unlimited tasks

Documentation

Use this task to send out account invitations to all the customers you already have on file, with the push of a button. Optionally, filter by customer tag.

Note: Account invitations are only intended to work with classic customer accounts.

This task sends the same Shopify-powered emails that are used when sending individual customer invitations, and uses the same Shopify email template. A custom subject and message are not required, but will be included when specified.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
mechanic/user/trigger
mechanic/shopify/bulk_operation
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
only invite customers with this tag , invitation email subject , invitation email body (multiline)
Code
{% assign only_invite_customers_with_this_tag = options.only_invite_customers_with_this_tag %}
{% assign invitation_email_subject = options.invitation_email_subject %}
{% assign invitation_email_body = options.invitation_email_body__multiline %}

{% if event.topic == "mechanic/user/trigger" %}
  {% assign search_query = "state:disabled" %}

  {% if only_invite_customers_with_this_tag != blank %}
    {%- capture search_query -%}
      {{ search_query }} AND tag:{{ only_invite_customers_with_this_tag | json }}
    {%- endcapture -%}
  {% endif %}

  {% capture bulk_operation_query %}
    query {
      customers(
        query: {{ search_query | json }}
      ) {
        edges {
          node {
            __typename
            id
          }
        }
      }
    }
  {% endcapture %}

  {% action "shopify" %}
    mutation {
      bulkOperationRunQuery(
        query: {{ bulk_operation_query | json }}
      ) {
        bulkOperation {
          id
          status
        }
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}

{% elsif event.topic == "mechanic/shopify/bulk_operation" %}
  {% if event.preview %}
    {% capture jsonl_string %}
      {"__typename":"Customer","id":"gid://shopify/Customer/1234567890"}
    {% endcapture %}

    {% assign bulkOperation = hash %}
    {% assign bulkOperation["objects"] = jsonl_string | parse_jsonl %}
  {% endif %}

  {% assign customers = bulkOperation.objects | where: "__typename", "Customer" %}

  {% for customer in customers %}
    {% 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 %}
  {% endfor %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more