# Assign an environment to a machine

Source: https://www.jawsdeploy.net/rest-api/machines-environment-assign | Section: Machines

Add one environment to a machine, leaving its other assignments alone.

`POST /api/machine/environment`

Assigns one environment to the machine. The machine's other environments are left untouched, so this is the endpoint for bringing a machine into a tier without having to know the rest of its assignments.

The call is **idempotent**: assigning an environment the machine already has succeeds and changes nothing, so a pipeline that reruns does not have to check first.

The environment must belong to the same workspace as the machine. A disabled environment can still be assigned - `enabled` controls whether the environment takes part in deployments, not whether it can be configured.

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machineId` | body | string | yes | ID of the machine, from [List machines](https://www.jawsdeploy.net/rest-api/machines-list). |
| `environmentId` | body | string | yes | ID of the environment, from [List environments](https://www.jawsdeploy.net/rest-api/environments-list). |

## Errors

| Status | Meaning |
|---|---|
| 400 | Invalid `machineId`. A machine that belongs to another organization is reported the same way as one that does not exist. |
| 400 | Missing `environmentId`, or an environment that does not belong to the machine's workspace. |
| 401 | Missing or invalid Basic auth credentials, or the service account lacks permission to manage machines in this workspace. |

Example request:

```
POST /api/machine/environment HTTP/1.1
Authorization: Basic <base64(...)>
Content-Type: application/json

{
  "machineId": "mch_web01",
  "environmentId": "env_prod"
}
```

Example response:

```
{}
```

