# Upsert phase environment

Source: https://www.jawsdeploy.net/rest-api/lifecycle-phase-environment-upsert | Section: Lifecycles

Attach an environment to a phase or change its trigger mode.

`PUT /api/lifecycle/phase/environment`

Adds an environment to a phase if not already present, otherwise updates its `howToTrigger` mode.

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `lifecycleId` | body | string | yes | ID of the lifecycle. |
| `phaseId` | body | string | yes | ID of the phase. |
| `environmentId` | body | string | yes | ID of the environment. |
| `howToTrigger` | body | string | no | `Manual` (the default) or `Automatic`. |

## Errors

| Status | Meaning |
|---|---|
| 400 | Invalid IDs or environment not in the workspace. |
| 401 | Missing or invalid Basic auth credentials, or the service account lacks the required role. |

Example request:

```
PUT /api/lifecycle/phase/environment

{ "lifecycleId": "lc_1", "phaseId": "ph_2", "environmentId": "env_b", "howToTrigger": "Automatic" }
```

Example response:

```
{}
```

