# Connect tenants to a project

Source: https://www.jawsdeploy.net/rest-api/project-tenants-connect | Section: Tenants

Connect many tenants to a project at once - by ID, by tag, or both - with the same environments.

`POST /api/project/tenants`

Connects the tenants you name, plus every active tenant with one of the tags, to the project. They all get the same environments.

Tenants that are already connected are left as they were - their environments are not changed - and are listed in `alreadyConnected`. To change the environments of one tenant use `PUT /api/tenant/project`.

The call is all or nothing: if a tenant, tag or environment is refused, no tenant is connected.

`missingValues` counts the required tenant variables each tenant still has to fill in. A new connection usually starts with some missing - set them with `PUT /api/tenant/variables`.

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `projectId` | body | string | yes | ID of the project. |
| `tenantIds` | body | array<string> | no | IDs of tenants in the project's workspace. Archived tenants are refused. |
| `tagIds` | body | array<string> | no | IDs of tags in the project's workspace. Every active tenant with at least one of these tags is connected. |
| `environmentIds` | body | array<string> | no | IDs of environments in the project's workspace the tenants can be deployed to. Leave out or send `[]` for none. |

## Errors

| Status | Meaning |
|---|---|
| 400 | Invalid `projectId`. A project that belongs to another organization is reported the same way as one that does not exist. |
| 400 | No tenants or tags were sent, a tenant, tag or environment is not in this workspace, or a tenant is archived. Nothing is connected. |
| 401 | Missing or invalid Basic auth credentials, or the service account lacks permission to manage tenants in this workspace. |

Example request:

```
POST /api/project/tenants HTTP/1.1
Authorization: Basic <base64(serviceAccountId:apiKey)>
Content-Type: application/json

{
  "projectId": "prj_abc123",
  "tenantIds": ["tnt_acme"],
  "tagIds": ["tag_eu"],
  "environmentIds": ["env_test", "env_prod"]
}
```

Example response:

```
{
  "projectId": "prj_abc123",
  "connected": [
    {
      "tenantId": "tnt_globex",
      "name": "Globex",
      "isArchived": false,
      "tags": [
        { "tagId": "tag_eu", "name": "Region/EU" }
      ],
      "environments": [
        { "environmentId": "env_test", "name": "Test" },
        { "environmentId": "env_prod", "name": "Production" }
      ],
      "missingValues": 2
    }
  ],
  "alreadyConnected": [
    {
      "tenantId": "tnt_acme",
      "name": "Acme",
      "isArchived": false,
      "tags": [],
      "environments": [
        { "environmentId": "env_prod", "name": "Production" }
      ],
      "missingValues": 0
    }
  ]
}
```

