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.
Try this taskWhen it runs
- Occurs when a user manually triggers the task
- Occurs when a bulk operation is completed
What you choose
- Only invite customers with this tag
- Custom subject
- Custom message
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.
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
mechanic/user/trigger
mechanic/shopify/bulk_operation
How task subscriptions work
Option types and flags
- Custom message (multiline)
Task code
{% if event.topic == "mechanic/user/trigger" %}
{% assign search_query = "customer_account_status = 'DISABLED'" %}
{% if options.only_invite_customers_with_this_tag %}
{%- capture search_query -%}
{{ search_query }} AND customer_tags CONTAINS '{{ options.only_invite_customers_with_this_tag }}'
{%- endcapture -%}
{% endif %}
{% assign cursor = nil %}
{% assign customers = array %}
{% comment %}
-- can query 1000 segment members at a time
{% endcomment %}
{% for n in (1..100) %}
{% capture query %}
query {
customerSegmentMembers(
first: 1000
after: {{ cursor | json }}
query: {{ search_query | json }}
) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
id
}
}
}
}
{% endcapture %}
{% assign result = query | shopify %}
{% if event.preview %}
{% capture result_json %}
{
"data": {
"customerSegmentMembers": {
"edges": [
{
"node": {
"id": "gid://shopify/CustomerSegmentMember/1234567890"
}
}
]
}
}
}
{% endcapture %}
{% assign result = result_json | parse_json %}
{% endif %}
{% assign customers
= result.data.customerSegmentMembers.edges
| map: "node"
| concat: customers
%}
{% if result.data.customers.pageInfo.hasNextPage %}
{% assign cursor = result.data.customers.pageInfo.endCursor %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{% comment %}
-- send invite to all customers with disabled accounts using REST (there is no equivalent GraphQL mutation)
{% endcomment %}
{% for customer in customers %}
{% action "shopify" %}
[
"post",
"/admin/customers/{{ customer.id | remove: "gid://shopify/CustomerSegmentMember/" }}/send_invite.json",
{
"customer_invite": {
"subject": {{ options.custom_subject | json }},
"custom_message": {{ options.custom_message__multiline | json }}
}
}
]
{% endaction %}
{% endfor %}
{% endif %}
Mechanic Liquid reference