# Testing HTTP Triggers in Simulation
Source: https://docs.chain.link/cre/guides/workflow/using-triggers/http-trigger/testing-in-simulation
Last Updated: 2025-11-10


During development, you can test your HTTP trigger workflows locally using the `cre workflow simulate` command. The simulator allows you to provide test payloads without setting up authorization keys or JWT authentication.

This guide focuses specifically on HTTP trigger simulation with detailed examples and scenarios. For a general overview of workflow simulation covering all trigger types, see [Simulating Workflows](/cre/guides/operations/simulating-workflows).

## Prerequisites

Before running a simulation:

- **CRE CLI installed**: You need the CRE CLI to run simulations. See [CLI Installation](/cre/getting-started/cli-installation) if you haven't installed it yet.
- **CRE account & authentication**: You must have a CRE account and be logged in with the CLI. See [Create your account](/cre/account/creating-account) and [Log in with the CLI](/cre/account/cli-login) for instructions.
- **HTTP trigger configured**: Your workflow must have an HTTP trigger handler registered. See [Configuration & Handler](/cre/guides/workflow/using-triggers/http-trigger/configuration) for setup instructions.

> **NOTE: No authorization required for simulation**
>
> During simulation, you can use an empty authorization configuration (e.g., `&http.Config{}` in Go or `trigger({})` in
> TypeScript). This simplifies local testing—just remember to add `authorizedKeys` before deploying.

## Basic simulation

To simulate a workflow with an HTTP trigger, run the `simulate` command from your project root:

```bash
cre workflow simulate <workflow-folder> --target <target-name>
```

**Example:**

```bash
cre workflow simulate my-http-workflow --target staging-settings
```

The simulator will detect your HTTP trigger and prompt you to select it from available triggers.

## Providing input data

You have three ways to provide JSON input to your HTTP trigger during simulation:

### 1. Interactive mode (default)

When you run the simulation without input flags, the CLI prompts you to enter JSON data:

```bash
$ cre workflow simulate my-http-workflow --target staging-settings

# Select the HTTP trigger when prompted
? Select a trigger to simulate: HTTP Trigger

# Enter your JSON input:
? Enter JSON input for the HTTP trigger:
{"userId": "123", "action": "purchase", "amount": 50}
```

The simulator converts your JSON into a payload and passes it to your callback function.

### 2. Inline JSON string

For non-interactive execution (useful for CI/CD or scripting), pass JSON directly using the `--http-payload` flag along with `--non-interactive` and `--trigger-index`:

```bash
cre workflow simulate my-http-workflow --non-interactive --trigger-index 0 --http-payload '{"userId":"123","action":"purchase","amount":50}' --target staging-settings
```

> **NOTE: Non-interactive requirements**
>
> The `--http-payload` flag requires `--non-interactive` mode. You must also specify `--trigger-index` to select which
> handler to run. The index is 0-based: if the handler with your HTTP trigger is the first handler defined in your
> `InitWorkflow` function, use `--trigger-index 0`; if it's the second, use `--trigger-index 1`, and so on.

> **NOTE: Escaping quotes**
>
> When passing JSON inline, use single quotes around the entire JSON string and double quotes for JSON keys and string
> values. On Windows, you may need to escape double quotes differently: `"{\"userId\":\"123\"}"`

### 3. Input from file

For complex payloads or reusable test data, store your JSON in a file and reference it in non-interactive mode.

**Option 1: File in workflow folder**

Create the payload file in your workflow directory:

**`my-http-workflow/test-payload.json`:**

```json
{
  "userId": "123",
  "action": "purchase",
  "amount": 50,
  "metadata": {
    "timestamp": "2025-11-10T10:00:00Z",
    "source": "mobile-app"
  }
}
```

**Simulate:**

```bash
cre workflow simulate my-http-workflow --non-interactive --trigger-index 0 --http-payload test-payload.json --target staging-settings
```

**Option 2: File at project root**

Create the payload file at your project root. Simulate (using `../` to reference the parent directory):

```bash
cre workflow simulate my-http-workflow --non-interactive --trigger-index 0 --http-payload ../test-payload.json --target staging-settings
```

> **NOTE: File paths are relative to the workflow folder**
>
> The CLI resolves file paths relative to the **workflow folder** you're simulating. Use just the filename for files in
> the workflow folder, or `../filename.json` for files at the project root.

## Example workflow simulation

Let's simulate a complete workflow that processes HTTP requests.

**Setup your config file:**

For this example, create a `config.staging.json` file with:

```json
{
  "minimumAmount": 10
}
```

This configuration sets the minimum purchase amount to 10, which we'll test with different scenarios.

**Workflow code:**

<CodeHighlightBlockMulti
  languages={{
  go: {
    code: simulationExampleGo,
    title: "HTTP Trigger Simulation Example",
  },
  ts: {
    code: simulationExampleTs,
    title: "HTTP Trigger Simulation Example",
  },
}}
/>

**Run the simulation:**

```bash
cre workflow simulate my-http-workflow --non-interactive --trigger-index 0 --http-payload '{"userId":"user_123","action":"purchase","amount":100}' --target staging-settings
```

**Expected output:**

```
Workflow compiled
2025-11-10T11:28:25Z [SIMULATION] Simulator Initialized

2025-11-10T11:28:25Z [SIMULATION] Running trigger trigger=http-trigger@1.0.0-alpha
2025-11-10T11:28:25Z [USER LOG] Processing purchase for user user_123
2025-11-10T11:28:25Z [USER LOG] Processing amount: 100

Workflow Simulation Result:
 "Successfully processed purchase"

2025-11-10T11:28:25Z [SIMULATION] Execution finished signal received
2025-11-10T11:28:25Z [SIMULATION] Skipping WorkflowEngineV2
```

## Testing different scenarios

Use simulation to test various input scenarios:

### Valid request

```bash
cre workflow simulate my-http-workflow --non-interactive --trigger-index 0 --http-payload '{"userId":"123","action":"purchase","amount":100}' --target staging-settings
```

### Invalid input (below minimum)

```bash
cre workflow simulate my-http-workflow --non-interactive --trigger-index 0 --http-payload '{"userId":"123","action":"purchase","amount":5}' --target staging-settings
```

**Expected output:**

```
Workflow compiled
2025-11-10T11:34:38Z [SIMULATION] Simulator Initialized

2025-11-10T11:34:38Z [SIMULATION] Running trigger trigger=http-trigger@1.0.0-alpha
2025-11-10T11:34:38Z [USER LOG] Processing purchase for user 123
2025-11-10T11:34:38Z [USER LOG] Amount 5 below minimum 10

Workflow Simulation Result:
 "Amount too low"

2025-11-10T11:34:38Z [SIMULATION] Execution finished signal received
2025-11-10T11:34:38Z [SIMULATION] Skipping WorkflowEngineV2
```

### Missing fields

```bash
cre workflow simulate my-http-workflow --non-interactive --trigger-index 0 --http-payload '{"userId":"123","action":"purchase"}' --target staging-settings
```

**Expected output:**

```
Workflow compiled
2025-11-10T11:37:57Z [SIMULATION] Simulator Initialized

2025-11-10T11:37:57Z [SIMULATION] Running trigger trigger=http-trigger@1.0.0-alpha
2025-11-10T11:37:57Z [USER LOG] Missing required fields

Workflow Simulation Result:
 "Error: Missing required fields (userId, action, amount)"

2025-11-10T11:37:57Z [SIMULATION] Execution finished signal received
2025-11-10T11:37:57Z [SIMULATION] Skipping WorkflowEngineV2
```

This helps you verify error handling and edge cases before deployment.

## Simulation vs production behavior

| Aspect                     | Simulation                          | Production                              |
| -------------------------- | ----------------------------------- | --------------------------------------- |
| **Authorization**          | Not required (empty config allowed) | Required (`authorizedKeys` must be set) |
| **Signature verification** | Skipped                             | Strictly enforced                       |
| **Execution**              | Immediate, synchronous              | Asynchronous via DON                    |
| **Logs**                   | Printed to terminal                 | Available in CRE UI                     |

> **CAUTION: Add authorization before deploying**
>
> Simulation allows empty authorization configs for convenience, but **deployed workflows require `authorizedKeys`**.
> The CLI will reject deployments with HTTP triggers that lack authorization configuration.

## Next steps

Once you've tested your workflow locally:

1. **Add authorization**: Configure `authorizedKeys` in your HTTP trigger for production
2. **Deploy your workflow**: Use [`cre workflow deploy`](/cre/guides/operations/deploying-workflows) to register it
3. **Trigger it in production**: Follow the [Triggering Deployed Workflows](/cre/guides/workflow/using-triggers/http-trigger/triggering-deployed-workflows) guide