Hook context
When building e-commerce integrations, your hooks often need to behave differently during testing or know which store is executing them. Hook context provides this environmental awareness to your hooks.
What is hook context?
Hook context is a parameter of the hook function that provides information about the hook's environment, like test mode status and store details.
Available properties
| env: object | Environment variables injected into the hook |
| isTestMode: boolean | Determines whether the hook is run in test mode |
| shopifyDomain: string | The domain of the store |
Common use cases
Here's how to use hook context to create smarter hooks:
module.exports = async function (payload, actions, context) {
// Use different API endpoints based on test/production mode
const api = context.isTestMode ?
'https://dev.myapi.com' :
'https://myapi.com';
// Include store information in API calls
const { data } = await actions.http.post(api, {
store: context.shopifyDomain,
payload: payload
});
}Best Practices
- Check isTestMode when making external API calls
- Use shopifyDomain for logging and tracking store-specific issues