> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Write Your First Action Module

> Build your first Auth0 Action Module in the Auth0 Dashboard by creating the module, adding secrets and NPM dependencies, publishing a version, and using it to send logs to an external service.

## Get Started

Use the quickstart to write an Action Module and use it from an Action to send logs to an external service.

### 1. Create an Action Module

To use an Action Module from a specific Action, you first need to create the Action Module and then add/use it in an Action.

> [tab] Dashboard
>
> 1. Navigate to [Auth0 Dashboard > Actions > Library](https://manage.auth0.com/#/actions/library) then select **Modules**.
> 2. Select **Create Module**.
> 3. Enter a **Name**.
> 4. Select **Create**.
>
> ![Actions Modules - New Action Module](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/customize/actions/modules/actions-modules-new-module.png)

> [tab] Management API
>
> 1. [Get a Management API Access Token](/docs/docs/secure/tokens/access-tokens/management-api-access-tokens) with the `create:actions` scope.
> 2. Call [Create an Actions Module](/docs/docs/api/management/v2/actions/post-action-module):
>
> ```shell theme={null}
> curl -L 'https://{yourDomain}/api/v2/actions/modules' \
>   -H 'Content-Type: application/json' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
>   -d '{
>     "name": "logger",
>     "code": "module.exports = {};",
>     "api_version": "1",
>     "publish": false
>   }'
> ```
>
> Auth0 returns the new Action Module, including its `id`, which you use to reference the module in later steps.

> [tab] Auth0 CLI
>
> Actions Modules are not natively exposed by the `auth0-cli` command set, so use [`auth0 api`](https://auth0.github.io/auth0-cli/auth0_api.html) to call the Management API directly. Some calls require additional scopes — run `auth0 login --scopes create:actions,read:actions,update:actions` first if needed.
>
> Call [Create an Actions Module](/docs/docs/api/management/v2/actions/post-action-module) with `auth0 api`:
>
> ```shell theme={null}
> auth0 api post actions/modules --data '{
>   "name": "logger",
>   "code": "module.exports = {};",
>   "api_version": "1",
>   "publish": false
> }'
> ```
>
> Auth0 returns the new Action Module, including its `id`, which you use to reference the module in later steps.

> [tab] Terraform
>
> Read the [`auth0_action_module`](https://registry.terraform.io/providers/auth0/auth0/latest/docs/resources/action_module) resource documentation to learn more.
>
> 1. Add the following resource to a `.tf` file, referencing the module's code from a file:
>
> ```terraform title="action-modules/logger.tf" theme={null}
> resource "auth0_action_module" "logger" {
>   name = "logger"
>   code = file("${path.module}/action-modules/logger/code.js")
> }
> ```
>
> 2. Create the module's code file at `action-modules/logger/code.js`:
>
> ```javascript title="action-modules/logger/code.js" theme={null}
> module.exports = {};
> ```
>
> 3. Run `terraform apply`.
>
> You will expand the code file and this resource with secrets in the following steps.

> [tab] Auth0 Deploy CLI
>
> > [tab] YAML
> >
> > 1. Create the module's code file at `action-modules/logger/code.js`:
> >
> > ```javascript title="action-modules/logger/code.js" theme={null}
> > module.exports = {};
> > ```
> >
> > 2. Add an `actionModules` entry to `tenant.yaml`:
> >
> > ```yaml title="tenant.yaml" theme={null}
> > actionModules:
> >   - name: logger
> >     code: ./action-modules/logger/code.js
> > ```
> >
> > 3. Deploy the configuration:
> >
> > ```shell theme={null}
> > a0deploy import -c=config.json --input_file=tenant.yaml
> > ```
>
> > [tab] Directory (JSON)
> >
> > 1. Create the module's configuration file at `action-modules/logger.json`:
> >
> > ```json title="action-modules/logger.json" theme={null}
> > {
> >   "name": "logger",
> >   "code": "./action-modules/logger/code.js"
> > }
> > ```
> >
> > 2. Create the module's code file at `action-modules/logger/code.js`:
> >
> > ```javascript title="action-modules/logger/code.js" theme={null}
> > module.exports = {};
> > ```
> >
> > 3. Deploy the configuration:
> >
> > ```shell theme={null}
> > a0deploy import -c=config.json --input_file=local.
> > ```

### 2. Add a Secret

Each Action Module can contain secret key/values pairs. Use these to hold sensitive information, such as API Keys, certificates, and values that may change across environments.

> [tab] Dashboard
>
> Next, store the external service URL as a Secret.
>
> 1. Select the \*\*\*\* icon from the code editor's left sidebar.
> 2. Select **Add Secret**.
> 3. Enter the **Name** as `SERVICE_URL`.
> 4. Enter the external service URL at the **Value** field.
> 5. Select **Create**.
>
> ![Actions Modules - Secret added](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/customize/actions/modules/actions-modules-secret.png)
>
> Auth0 adds the Secret to the Action Module Secret list.

> [tab] Management API
>
> Next, store the external service URL as a Secret. Call [Update an Actions Module](/docs/docs/api/management/v2/actions/patch-action-module) with the `update:actions` scope:
>
> ```shell theme={null}
> curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
>   -H 'Content-Type: application/json' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
>   -d '{
>     "secrets": [
>       { "name": "SERVICE_URL", "value": "https://example.com/logs" }
>     ]
>   }'
> ```
>
> Each `PATCH` call replaces the entire `secrets` array on the module's draft, so include every Secret the module needs, not just the one you are adding.

> [tab] Auth0 CLI
>
> Next, store the external service URL as a Secret. Call [Update an Actions Module](/docs/docs/api/management/v2/actions/patch-action-module) with `auth0 api`:
>
> ```shell theme={null}
> auth0 api patch actions/modules/{moduleId} --data '{
>   "secrets": [
>     { "name": "SERVICE_URL", "value": "https://example.com/logs" }
>   ]
> }'
> ```
>
> Each call replaces the entire `secrets` array on the module's draft, so include every Secret the module needs, not just the one you are adding.

> [tab] Terraform
>
> Next, store the external service URL as a Secret using a `secrets` block:
>
> ```terraform title="action-modules/logger.tf" theme={null}
> resource "auth0_action_module" "logger" {
>   name = "logger"
>   code = file("${path.module}/action-modules/logger/code.js")
>
>   secrets {
>     name  = "SERVICE_URL"
>     value = "https://example.com/logs"
>   }
> }
> ```
>
> We do not support partial management of `secrets`. Each `terraform apply` sends the complete list of secrets defined on the resource.

> [tab] Auth0 Deploy CLI
>
> Next, store the external service URL as a Secret.
>
> > [tab] YAML
> >
> > Add a `secrets` array to the module's entry in `tenant.yaml`:
> >
> > ```yaml highlight={3-5} title="tenant.yaml" theme={null}
> > actionModules:
> >   - name: logger
> >     secrets:
> >       - name: SERVICE_URL
> >         value: ##SERVICE_URL##
> >     code: ./action-modules/logger/code.js
> > ```
>
> > [tab] Directory (JSON)
> >
> > Add a `secrets` array to `action-modules/logger.json`:
> >
> > ```json highlight={3-5} title="action-modules/logger.json" theme={null}
> > {
> >   "name": "logger",
> >   "secrets": [
> >     { "name": "SERVICE_URL", "value": "##SERVICE_URL##" }
> >   ],
> >   "code": "./action-modules/logger/code.js"
> > }
> > ```
>
> The `##SERVICE_URL##` placeholder is resolved through [keyword replacement](https://github.com/auth0/auth0-deploy-cli/blob/master/docs/keyword-replacement.md) at deploy time, so the actual value never lives in your configuration file.

**Extra Step:** Repeat the steps to store an `API_KEY` as a Secret that you will send in the headers to the external service in each request.

Once you create a Secret, Auth0 never reveals its value. Auth0 encrypts all Secrets and stores them securely.

Each **Action Module Secret** is independent from other **Actions Modules** and **Actions Secrets**.

Use **Secrets** at the Action Module by typing `actions.secrets.[secret_key]`.

### 3. Add Custom Logic

Now, add the following code to your Action Module.

> [tab] Dashboard
>
> Add the following code to your Action Module:
>
> ```javascript theme={null}
> module.exports = {
>   sendLog: async (code, message) => {
>     try {
>       await fetch(actions.secrets.SERVICE_URL, {
>         method: 'POST',
>         headers: {
>           'X-API-Key': actions.secrets.API_KEY,
>         },
>         body: JSON.stringify({
>           code,
>           message
>         }),
>       });
>
>       console.log({
>         code,
>         message
>       });
>     } catch (err) {
>       throw new Error('External service failure');
>     }
>
>     return;
>   }
> };
> ```

> [tab] Management API
>
> Call [Update an Actions Module](/docs/docs/api/management/v2/actions/patch-action-module) with the following request:
>
> ```shell theme={null}
> curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
>   -H 'Content-Type: application/json' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
>   -d @code-update.json
> ```
>
> Where `code-update.json` contains the module's `code` as a JSON-escaped string:
>
> ```json title="code-update.json" theme={null}
> {
>   "code": "module.exports = {\n  sendLog: async (code, message) => {\n    try {\n      await fetch(actions.secrets.SERVICE_URL, {\n        method: 'POST',\n        headers: {\n          'X-API-Key': actions.secrets.API_KEY,\n        },\n        body: JSON.stringify({ code, message }),\n      });\n\n      console.log({ code, message });\n    } catch (err) {\n      throw new Error('External service failure');\n    }\n\n    return;\n  }\n};"
> }
> ```

> [tab] Auth0 CLI
>
> Save the module's code to `code-update.json`:
>
> ```json title="code-update.json" theme={null}
> {
>   "code": "module.exports = {\n  sendLog: async (code, message) => {\n    try {\n      await fetch(actions.secrets.SERVICE_URL, {\n        method: 'POST',\n        headers: {\n          'X-API-Key': actions.secrets.API_KEY,\n        },\n        body: JSON.stringify({ code, message }),\n      });\n\n      console.log({ code, message });\n    } catch (err) {\n      throw new Error('External service failure');\n    }\n\n    return;\n  }\n};"
> }
> ```
>
> Then pipe it into [Update an Actions Module](/docs/docs/api/management/v2/actions/patch-action-module) via `auth0 api`:
>
> ```shell theme={null}
> cat code-update.json | auth0 api patch actions/modules/{moduleId}
> ```

> [tab] Terraform
>
> 1. Update the module's code file at `action-modules/logger/code.js`:
>
> ```javascript title="action-modules/logger/code.js" theme={null}
> module.exports = {
>   sendLog: async (code, message) => {
>     try {
>       await fetch(actions.secrets.SERVICE_URL, {
>         method: 'POST',
>         headers: {
>           'X-API-Key': actions.secrets.API_KEY,
>         },
>         body: JSON.stringify({
>           code,
>           message
>         }),
>       });
>
>       console.log({
>         code,
>         message
>       });
>     } catch (err) {
>       throw new Error('External service failure');
>     }
>
>     return;
>   }
> };
> ```
>
> 2. The `auth0_action_module` resource's `code` attribute already references this file, so run `terraform apply` to apply the change.

> [tab] Auth0 Deploy CLI
>
> Update `action-modules/logger/code.js` with the module's logic:
>
> ```javascript title="action-modules/logger/code.js" theme={null}
> module.exports = {
>   sendLog: async (code, message) => {
>     try {
>       await fetch(actions.secrets.SERVICE_URL, {
>         method: 'POST',
>         headers: {
>           'X-API-Key': actions.secrets.API_KEY,
>         },
>         body: JSON.stringify({
>           code,
>           message
>         }),
>       });
>
>       console.log({
>         code,
>         message
>       });
>     } catch (err) {
>       throw new Error('External service failure');
>     }
>
>     return;
>   }
> };
> ```

Be aware of:

* [Coding Guidelines](/docs/docs/customize/actions/action-coding-guidelines#actions-modules)
* [Limitations](/docs/docs/customize/actions/limitations#actions-modules)

### 4. Save the Draft

You can save a draft of your Action Module.

> [tab] Dashboard
>
> 1. Select **Save Draft**.
>
> ![Actions Modules - Draft saved](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/customize/actions/modules/actions-modules-draft.png)

> [tab] Management API
>
> There is no separate "save" call. Every [Update an Actions Module](/docs/docs/api/management/v2/actions/patch-action-module) request in the previous steps already persisted your changes to the module's draft. You can confirm this with [Get an Actions Module](/docs/docs/api/management/v2/actions/get-action-module):
>
> ```shell theme={null}
> curl -L 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}'
> ```
>
> The response's `all_changes_published` field is `false`, confirming the draft has unpublished changes.

> [tab] Auth0 CLI
>
> There is no separate "save" call. Every `auth0 api patch actions/modules/{moduleId}` request in the previous steps already persisted your changes to the module's draft. You can confirm this with [Get an Actions Module](/docs/docs/api/management/v2/actions/get-action-module):
>
> ```shell theme={null}
> auth0 api get actions/modules/{moduleId}
> ```
>
> The response's `all_changes_published` field is `false`, confirming the draft has unpublished changes.

> [tab] Terraform
>
> There is no separate "save" step. The `terraform apply` you ran in the previous steps already updated the module's draft. The draft has no effect on Actions already using a published version of the module.

> [tab] Auth0 Deploy CLI
>
> Set `all_changes_published` to `false` on the module's entry.
>
> There is no separate "save" step.
>
> > [tab] YAML
> >
> > Update `tenant.yaml`:
> >
> > ```yaml highlight={3} title="tenant.yaml" theme={null}
> > actionModules:
> >   - name: logger
> >     all_changes_published: false
> >     secrets:
> >       - name: SERVICE_URL
> >         value: ##SERVICE_URL##
> >     code: ./action-modules/logger/code.js
> > ```
> >
> > Redeploy the configuration to publish the change:
> >
> > ```shell theme={null}
> > a0deploy import -c=config.json --input_file=tenant.yaml
> > ```
>
> > [tab] Directory (JSON)
> >
> > Update `action-modules/logger.json`:
> >
> > ```json highlight={2} title="action-modules/logger.json" theme={null}
> > {
> >   "all_changes_published": false,
> >   "name": "logger",
> >   "secrets": [
> >     { "name": "SERVICE_URL", "value": "##SERVICE_URL##" }
> >   ],
> >   "code": "./action-modules/logger/code.js"
> > }
> > ```
> >
> > Redeploy the configuration to publish the change:
> >
> > ```shell theme={null}
> > a0deploy import -c=config.json --input_file=local.
> > ```

This saves your Action Module without publishing a new version, so it does not affect Actions using it.

### 5. Publish the Action Module

Once you are satisfied with the Action Module code, it’s time to **Publish** it.

> [tab] Dashboard
>
> 1. Select **Publish**.
>
> Publishing an Action Module takes a snapshot of it at that time and records it as an **Action Module Version**.
>
> 2. Select **View Version History**.
>
> ![Actions Modules - Version History](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/customize/actions/modules/actions-modules-published-version.png)
>
> Auth0 displays the list of Action Module Versions including the draft.

> [tab] Management API
>
> Call [Create an Actions Module Version](/docs/docs/api/management/v2/actions/post-action-module-version), which takes a snapshot of the current draft and publishes it:
>
> ```shell theme={null}
> curl -L -X POST 'https://{yourDomain}/api/v2/actions/modules/{moduleId}/versions' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}'
> ```
>
> Auth0 returns the new **Action Module Version**, including its `id` and `version_number`. You'll reference this `id` as the `module_version_id` when adding the module to an Action.

> [tab] Auth0 CLI
>
> Call [Create an Actions Module Version](/docs/docs/api/management/v2/actions/post-action-module-version) with `auth0 api`, which takes a snapshot of the current draft and publishes it:
>
> ```shell theme={null}
> auth0 api post actions/modules/{moduleId}/versions
> ```
>
> Auth0 returns the new **Action Module Version**, including its `id` and `version_number`. You'll reference this `id` as the `module_version_id` when adding the module to an Action.

> [tab] Terraform
>
> Set `publish` to `true` on the resource, then run `terraform apply`:
>
> ```terraform highlight={4} title="action-modules/logger.tf" theme={null}
> resource "auth0_action_module" "logger" {
>   name    = "logger"
>   code    = file("${path.module}/action-modules/logger/code.js")
>   publish = true
>
>   secrets {
>     name  = "SERVICE_URL"
>     value = "https://example.com/logs"
>   }
> }
> ```
>
> Publishing creates a new **Action Module Version** from the current draft. Terraform exposes the published version's ID as the `version_id` computed attribute, which you reference from `auth0_action` resources as `module_version_id`.

> [tab] Auth0 Deploy CLI
>
> Set `all_changes_published` to `true` on the module's entry.
>
> > [tab] YAML
> >
> > Update `tenant.yaml`:
> >
> > ```yaml highlight={3} title="tenant.yaml" theme={null}
> > actionModules:
> >   - name: logger
> >     all_changes_published: true
> >     secrets:
> >       - name: SERVICE_URL
> >         value: ##SERVICE_URL##
> >     code: ./action-modules/logger/code.js
> > ```
> >
> > Redeploy the configuration to publish the change:
> >
> > ```shell theme={null}
> > a0deploy import -c=config.json --input_file=tenant.yaml
> > ```
>
> > [tab] Directory (JSON)
> >
> > Update `action-modules/logger.json`:
> >
> > ```json highlight={2} title="action-modules/logger.json" theme={null}
> > {
> >   "all_changes_published": true,
> >   "name": "logger",
> >   "secrets": [
> >     { "name": "SERVICE_URL", "value": "##SERVICE_URL##" }
> >   ],
> >   "code": "./action-modules/logger/code.js"
> > }
> > ```
> >
> > Redeploy the configuration to publish the change:
> >
> > ```shell theme={null}
> > a0deploy import -c=config.json --input_file=local.
> > ```
>
> This publishes a new **Action Module Version** from the current draft after applying your changes.

You are now able to start using the Action Module in an Action.

Each **Action** must explicitly reference the **Action Module Version**, preventing automatic upgrades that could introduce unexpected errors.

### 6. Add the Action Module in an Action

Next, add the Action Module in an Action.

> [tab] Dashboard
>
> 1. Navigate to [Auth0 Dashboard > Actions > Library](https://manage.auth0.com/#/actions/library) then select a specific **Action**.
> 2. Once at the Action Editor, select the \*\*\*\* icon from the left sidebar.
> 3. Select **Add Module**.
> 4. Select a Module **Name** and **Version**.
> 5. Select **Add**.
>
> ![Actions - Add Action Module](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/customize/actions/modules/actions-modules-add-module.png)

> [tab] Management API
>
> Call [Update an Action](/docs/docs/api/management/v2/actions/patch-action) with the module's `module_id` and `module_version_id` from the previous step:
>
> ```shell theme={null}
> curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/actions/{actionId}' \
>   -H 'Content-Type: application/json' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
>   -d '{
>     "modules": [
>       {
>         "module_id": "{moduleId}",
>         "module_version_id": "{moduleVersionId}"
>       }
>     ]
>   }'
> ```

> [tab] Auth0 CLI
>
> [`auth0 actions update`](https://auth0.github.io/auth0-cli/auth0_actions_update.html) has no flag for Action Modules, so call [Update an Action](/docs/docs/api/management/v2/actions/patch-action) directly with `auth0 api`, using the module's `module_id` and `module_version_id` from the previous step:
>
> ```shell theme={null}
> auth0 api patch actions/actions/{actionId} --data '{
>   "modules": [
>     {
>       "module_id": "{moduleId}",
>       "module_version_id": "{moduleVersionId}"
>     }
>   ]
> }'
> ```

> [tab] Terraform
>
> Add a `modules` block to the `auth0_action` resource, referencing the module and its published version. Keep the `code` attribute pointing at the Action's own code file:
>
> ```terraform highlight={3,5-8} title="actions/my-action.tf" theme={null}
> resource "auth0_action" "my_action" {
>   name = "my-action"
>   code = file("${path.module}/actions/my-action/code.js")
>
>   modules {
>     module_id         = auth0_action_module.logger.id
>     module_version_id = auth0_action_module.logger.version_id
>   }
>
>   supported_triggers {
>     id      = "post-login"
>     version = "v3"
>   }
> }
> ```

> [tab] Auth0 Deploy CLI
>
> Add a `modules` array to the Action's configuration, referencing the module by name and version number.
>
> > [tab] YAML
> >
> > Add the `modules` array to the Action's entry in `tenant.yaml`:
> >
> > ```yaml highlight={7-9} title="tenant.yaml" theme={null}
> > actions:
> >   - name: my-action
> >     code: ./actions/my-action/code.js
> >     supported_triggers:
> >       - id: post-login
> >         version: v3
> >     modules:
> >       - module_name: logger
> >         module_version_number: 1
> > ```
>
> > [tab] Directory (JSON)
> >
> > Add the `modules` array to the Action's configuration file (for example, `actions/my-action.json`):
> >
> > ```json highlight={2-5} title="actions/my-action.json" theme={null}
> > {
> >   "modules": [
> >     { "module_name": "logger", "module_version_number": 1 }
> >   ],
> >   "name": "my-action",
> >   "code": "./actions/my-action/code.js",
> >   "supported_triggers": [
> >     { "id": "post-login", "version": "v3" }
> >   ]
> > }
> > ```
>
> The Deploy CLI resolves `module_name` and `module_version_number` to the module's real `module_id` and `module_version_id` at deploy time.

### 7. Use the Action Module in the Action

Now, let’s use the Action Module in the Action.

> [tab] Dashboard
>
> 1. Add the **require** statement.
>
> ```javascript theme={null}
> const logger = require('actions:logger');
> ```
>
> The **require** statement references the Action Module with the format **actions:\[module-name]**.
>
> 2. Add the call to `logger.sendLog` in the **Action function**, where you want to send logs.
>
> ```javascript theme={null}
> await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
> ```
>
> 3. Select **Deploy** the Action.
>
> ![Actions - Use Action Module](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/customize/actions/modules/actions-modules-use-module.png)

> [tab] Management API
>
> 1. Call [Update an Action](/docs/docs/api/management/v2/actions/patch-action) to add the `require` statement and the call to `logger.sendLog` to the Action's `code`:
>
> ```shell theme={null}
> curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/actions/{actionId}' \
>   -H 'Content-Type: application/json' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
>   -d @code-update.json
> ```
>
> Where `code-update.json` contains:
>
> ```json title="code-update.json" theme={null}
> {
>   "code": "const logger = require('actions:logger');\n\nexports.onExecutePostLogin = async (event, api) => {\n  await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');\n};"
> }
> ```
>
> 2. Call [Deploy an Action](/docs/docs/api/management/v2/actions/post-deploy-action):
>
> ```shell theme={null}
> curl -L -X POST 'https://{yourDomain}/api/v2/actions/actions/{actionId}/deploy' \
>   -H 'Authorization: Bearer {yourMgmtApiAccessToken}'
> ```

> [tab] Auth0 CLI
>
> 1. Update the Action's code file at `actions/my-action/code.js` with the `require` statement and the call to `logger.sendLog`:
>
> ```javascript title="actions/my-action/code.js" theme={null}
> const logger = require('actions:logger');
>
> exports.onExecutePostLogin = async (event, api) => {
>   await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
> };
> ```
>
> 2. Update the Action with [`auth0 actions update`](https://auth0.github.io/auth0-cli/auth0_actions_update.html) and deploy it with [`auth0 actions deploy`](https://auth0.github.io/auth0-cli/auth0_actions_deploy.html):
>
> ```shell theme={null}
> auth0 actions update {actionId} --code "$(cat actions/my-action/code.js)"
> auth0 actions deploy {actionId}
> ```

> [tab] Terraform
>
> 1. Update the Action's code file at `actions/my-action/code.js` with the `require` statement and the call to `logger.sendLog`:
>
> ```javascript title="actions/my-action/code.js" theme={null}
> const logger = require('actions:logger');
>
> exports.onExecutePostLogin = async (event, api) => {
>   await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
> };
> ```
>
> 2. Set `deploy` to `true` on the `auth0_action` resource, then run `terraform apply`:
>
> ```terraform highlight={3} title="actions/my-action.tf" theme={null}
> resource "auth0_action" "my_action" {
>   name    = "my-action"
>   deploy  = true
>   code    = file("${path.module}/actions/my-action/code.js")
>
>   modules {
>     module_id         = auth0_action_module.logger.id
>     module_version_id = auth0_action_module.logger.version_id
>   }
>
>   supported_triggers {
>     id      = "post-login"
>     version = "v3"
>   }
> }
> ```
>
> Setting `deploy = true` immediately creates a new, deployed version of the Action.

> [tab] Auth0 Deploy CLI
>
> 1. Add the `require` statement and the call to `logger.sendLog` to `actions/my-action/code.js`:
>
> ```javascript title="actions/my-action/code.js" theme={null}
> const logger = require('actions:logger');
>
> exports.onExecutePostLogin = async (event, api) => {
>   await logger.sendLog('logger_success', 'Your Action was able to use the Logger Action Module');
> };
> ```
>
> 2. Redeploy the configuration:
>
> ```shell theme={null}
> a0deploy import -c=config.json --input_file=local.
> ```

Remember to bind the Action to a Trigger.

> [!TIP]
>
> **Checkpoint**
>
> You should now have a fully functional **Action Module** being used by an **Action**.

***

## Advanced Usage

> [accordion] NPM Dependencies
>
> Each **Action Module** can add/use **[NPM Dependencies](https://www.npmjs.com/)**.
>
> > [tab] Dashboard
> >
> > 1. Select the \*\*\*\* icon from the code editor's left sidebar.
> > 2. Select **Add Dependency**.
> > 3. Enter the **Name** of the **NPM package**.
> > 4. Enter the **Version** of the **NPM package**.
> > 5. Select **Create**.
> >
> > ![Actions Modules - Dependency added](https://mintlify.s3.us-west-1.amazonaws.com/docs-dev/images/customize/actions/modules/actions-modules-dependency.png)
> >
> > Auth0 adds the Dependency to the Action Module Dependency list.
>
> > [tab] Management API
> >
> > Call [Update an Actions Module](/docs/docs/api/management/v2/actions/patch-action-module) with a `dependencies` array:
> >
> > ```shell theme={null}
> > curl -L -X PATCH 'https://{yourDomain}/api/v2/actions/modules/{moduleId}' \
> >   -H 'Content-Type: application/json' \
> >   -H 'Authorization: Bearer {yourMgmtApiAccessToken}' \
> >   -d '{
> >     "dependencies": [
> >       { "name": "lodash", "version": "4.17.21" }
> >     ]
> >   }'
> > ```
> >
> > As with `secrets`, each `PATCH` call replaces the entire `dependencies` array, so include every dependency the module needs.
>
> > [tab] Auth0 CLI
> >
> > Call [Update an Actions Module](/docs/docs/api/management/v2/actions/patch-action-module) with `auth0 api`, using a `dependencies` array:
> >
> > ```shell theme={null}
> > auth0 api patch actions/modules/{moduleId} --data '{
> >   "dependencies": [
> >     { "name": "lodash", "version": "4.17.21" }
> >   ]
> > }'
> > ```
> >
> > As with `secrets`, each call replaces the entire `dependencies` array, so include every dependency the module needs.
>
> > [tab] Terraform
> >
> > Add a `dependencies` block to the `auth0_action_module` resource, then run `terraform apply`:
> >
> > ```terraform highlight={4-7} title="action-modules/logger.tf" theme={null}
> > resource "auth0_action_module" "logger" {
> >   name = "logger"
> >   code = file("${path.module}/action-modules/logger/code.js")
> >
> >   dependencies {
> >     name    = "lodash"
> >     version = "4.17.21"
> >   }
> > }
> > ```
>
> > [tab] Auth0 Deploy CLI
> >
> > Add a `dependencies` array to the module's configuration.
> >
> > > [tab] YAML
> > >
> > > Add the `dependencies` array to the module's entry in `tenant.yaml`:
> > >
> > > ```yaml highlight={3-5} title="tenant.yaml" theme={null}
> > > actionModules:
> > >   - name: logger
> > >     dependencies:
> > >       - name: lodash
> > >         version: 4.17.21
> > >     code: ./action-modules/logger/code.js
> > > ```
> >
> > > [tab] Directory (JSON)
> > >
> > > Add the `dependencies` array to `action-modules/logger.json`:
> > >
> > > ```json highlight={2-4} title="action-modules/logger.json" theme={null}
> > > {
> > >   "dependencies": [
> > >     { "name": "lodash", "version": "4.17.21" }
> > >   ],
> > >   "name": "logger",
> > >   "code": "./action-modules/logger/code.js"
> > > }
> > > ```
>
> Use the listed **Dependencies** at the Action Module by requiring them through `require('[package-name]')`.
>
> When you save this Action, Auth0 resolves the latest version of your dependency and replaces it with a specific version number to keep future updates to the package from breaking your Action.
>
> You can provide a specific version instead of latest.


## Related topics

- [Modules](/docs/docs/customize/actions/modules.md)
