Event actions are powerful. They allow you to invoke other tasks as a response to an incoming event. And, because a single task can subscribe to multiple event topics, it means you can create multi-phase tasks that are executed over time.

Emitting an event creates a parent-child relationship between the originating event, and the event that was generated. Learn more about this.

For developers

Options

  • "topic" – required, must start with user/ and look like user/foo/bar 
  • "data" – required, can be any JSON value
  • "run_at" – optional, can be a UNIX timestamp integer, or any string that can be interpreted as a datetime
  • "task_ids" – optional, can be an array of task ID strings, allowing you to specify a whitelist of tasks that should be allowed to respond to this event; can alternatively be given as "task_id", with a single string value

To learn more about "run_at" and scheduling events, see: Can I schedule tasks for the future?

Example

This task emails a customer daily until their order is paid.

Subscriptions:

shopify/orders/create
user/orders/unpaid_reminder+1.day

Script:

{% if event.topic == "user/orders/unpaid_reminder" %}
  {% assign order = shop.orders[event.data.order_id] %}
{% endif %}

{% unless order.financial_status == "paid" %}
  {% action "email" %}
    {
      "to": {{ order.email | json }},
      "reply_to": {{ shop.customer_email | json }},
      "subject": "Order #{{ order.order_number }} still needs to be paid",
      "body": "Please get in touch, stat!",
      "from_display_name": {{ shop.name | json }}
    }
  {% endaction %}

  {% action "event" %}
    {
      "topic": "user/orders/unpaid_reminder",
      "task_id": {{ task.id | json }},
      "data": {
        "order_id": {{ order.id | json }}
      }
    }
  {% endaction %}
{% endunless %}
Did this answer your question?