What is a hook?

A hook is a javascript code snippet run in response to a webhook event.

Trigger event

It starts with a webhook event happening in the store, like a customer adding a product to the cart, completing a checkout, or requesting a refund.

When the trigger event is fired, the hook's code gets run.

Hook code

The hook code is a CommonJS module that needs to export a javascript function which is run in response to trigger event.

The module may contain other functions or variable declarations, and it can call any number of actions.

The exported function has the following signature:

module.exports = async function(payload, actions, context) {
	// Your hook code is here with actions
}

Parameters of the function:

The hook runs in a sandbox, and importing other javascript modules is disabled.

Deployment states

A hook can be active or inactive.

An active hook is live, and it responds to its trigger event.
An active hook can be tested, and its trigger event or its properties can be changed at any time.

An inactive hook is dormant, so it doesn't respond to its trigger event.
Inactive hooks can be tested or modified any way.

Run logs

Active hooks generate logs upon every run triggered by a trigger event.

The run logs can be filtered by:

  • date
  • resource id
  • status (successful or failed).

A run log may contain actions, errors, or debug log entries.