# The onEvent function
URL: https://docs.awellhealth.com/docs/extensions/on-event

> For the complete documentation index, see [llms.txt](https://docs.awellhealth.com/llms.txt).



`onEvent` is called whenever orchestration, or a design-time preview, activates a custom action. Awell
publishes a message, the extension server receives it, finds the right custom action, and calls its
`onEvent`.

```javascript
export const myAction = {
  // …
  onEvent: async ({ payload, onComplete, onError, helpers }) => {
    // Do something here
  },
};
```

## What the payload carries [#what-the-payload-carries]

* the values of the extension's [settings](/docs/extensions/extension-settings)
* the values of the action's [fields](/docs/extensions/action-fields)
* patient and care flow data

## Every action must call onComplete or onError [#every-action-must-call-oncomplete-or-onerror]

`onComplete` and `onError` hand control back to the design preview or the orchestration engine.

An action that returns without calling either leaves the care flow waiting on an activity that never
finishes, and the patient waits with it. Wrap the logic so every path, including a thrown exception, ends
in one of the two.

## Helpers: HTTPS requests and the Awell SDK [#helpers-https-requests-and-the-awell-sdk]

* `httpsAgent` makes outbound HTTPS requests.
* `AwellSdk` talks back to Awell's own API.

## onEvent replaced onActivityCreated [#onevent-replaced-onactivitycreated]

`onActivityCreated` has been deprecated since 1 September 2024. Older extensions may still call it; see
[onActivityCreated](/docs/extensions/on-activity-created).

## Next steps [#next-steps]

**Next:** [Test your extension](/docs/extensions/test-your-extension).
