# 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"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lilbobbytables.gitbook.io/mycrt-user-guide/rest-api/sharing-environments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
