> For the complete documentation index, see [llms.txt](https://lilbobbytables.gitbook.io/mycrt-user-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lilbobbytables.gitbook.io/mycrt-user-guide/rest-api/sharing-environments.md).

# Sharing Environments

## Invite User to Environment

Given a user email, gives another user access to a specific environment. Returns the information for the environment.

```
POST api/environment/invites
```

#### Permissions

User must be logged in. User must be an admin of the environment.

#### Sample Request Body

```typescript
{
 "environmentId": 1,
 "userEmail": "user@email.com"
}
```

#### Success Response

```
200 OK
```

```typescript
{
    "id": 2,
    "environmentId": 1,
    "userId": 1,
    "isAdmin": false,
    "inviteCode": "XXXXXXXX",
    "accepted": false,
    "createdAt": 1526761026983
}
```

#### Error Response

```
400 BAD REQUEST
```

```typescript
{
    "code": 400,
    "message": "User user2@email.com does not exist"
}
```

```
403 FORBIDDEN
```

```typescript
{
    "code": 403,
    "message": "Only environment administrators can invite"
}
```

```
404 NOT FOUND
```

```typescript
{
    "code": 404,
    "message": "Environment X does not exist"
}
```

## Accept Invite to Environment

User accepts the invitation to an environment so that they have access to it.

```
PUT api/environments/invites/accept
```

#### Permissions

User must be logged in.&#x20;

#### Sample Request Body

```typescript
{
 "inviteCode": "XXXXXXXX"
}
```

#### Success Response

```
200 OK
```

```typescript
{
    "id": 1,
    "envName": "Test Environment 1",
    "ownerId": 1,
    "keysId": 1,
    "keysName": "myKeys",
    "accessKey": "XXXXXXXXXX",
    "secretKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "region": "us-east-2",
    "dbName": "DB",
"host" : "xxxxx.xxxxx.us-east-2.rds.amazonaws.com",
    "user": "user",
    "pass": "pass",
    "instance": "XXXXXXX",
    "parameterGroup": "paramGroup",
    "bucket": "testBucket",
    "prefix": null
}
```

#### Error Response

```
404 NOT FOUND
```

```typescript
{
    "code": 404,
    "message": "Environment X does not exist"
}
```

```
409 CONFLICT
```

```typescript
{
    "code": 409,
    "message": "Invite has already been accepted"
}
```

```typescript
{
    "code": 409,
    "message": "Invitation has expired"
}
```
