# Captures

## Get All Captures

Gets information for all of the captures that a user has access to.

```
GET /api/captures
```

#### Permissions

User must be logged in. User must be a member of the environment.

#### Success Response

```
200 OK
```

```typescript
[
    {
        "id": 1,
        "name": "myCapture",
        "start": "2018-05-19T22:06:53.000Z",
        "scheduledStart": null,
        "scheduledEnd": null,
        "end": "2018-05-19T22:20:39.000Z",
        "status": "DONE",
        "envId": 1,
        "type": "CAPTURE",
        "reason": null
    }
]
```

#### Error Response

```
404 NOT FOUND
```

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

## Get a Specific Capture

Gets the information of a specific capture associated with an environment.

```
GET /api/captures/{id}
```

#### Permissions

User must be logged in. User must be a member of the environment.

#### Query Params <a href="#query-params" id="query-params"></a>

| Param        | Description              | Optional/Required |
| ------------ | ------------------------ | ----------------- |
| id=\[number] | id of the capture to get | Required          |

#### Success Response

```
200 OK
```

```typescript
{
    "id": 1,
    "name": "myCapture",
    "start": "2018-05-19T22:06:53.000Z",
    "scheduledStart": null,
    "scheduledEnd": null,
    "end": "2018-05-19T22:20:39.000Z",
    "status": "DONE",
    "envId": 1,
    "type": "CAPTURE",
    "reason": null
}
```

#### Error Response

```
404 NOT FOUND
```

```typescript
{
    "code": 404,
    "message": "Capture's environment not found"
}
```

## Get Metrics for a Specific Capture

Gets the CloudWatch metrics associated with specific capture associated with an environment.

```
GET /api/captures/{id}/metrics
```

#### Permissions

User must be logged in. User must be a member of the environment.

#### Query Params <a href="#query-params" id="query-params"></a>

| Param        | Description                          | Optional/Required |
| ------------ | ------------------------------------ | ----------------- |
| id=\[number] | id of the capture to get metrics for | Required          |

#### Success Response

```
200 OK
```

```typescript
[
    {
        "label": "ReadIOPS",
        "type": "READ IOPS",
        "displayName": "READ IOPS",
        "dataPoints": [
            {
                "Timestamp": "2018-05-17T00:53:00.000Z",
                "Maximum": 0.06666888896296544,
                "Unit": "Count/Second"
            }
    }
]
```

#### Error Response

```
404 NOT FOUND
```

```typescript
{
    "code": 404,
    "message": "Capture's environment not found"
}
```

## Stop a Capture

Stops a specific capture associated with a given environment. The capture must be in the “Running” state before it is stopped.

```
POST /api/captures/{id}/stop
```

#### Permissions

User must be logged in. User must either be the owner of the capture or be an  admin of the environment.

#### Query Params <a href="#query-params" id="query-params"></a>

| Param        | Description               | Optional/Required |
| ------------ | ------------------------- | ----------------- |
| id=\[number] | id of the capture to stop | Required          |

#### Success Response

```
200 OK
```

#### Error Response

```
404 NOT FOUND
```

```typescript
{
    "code": 404,
    "message": "Capture not found"
}
```

```
409 CONFLICT
```

```typescript
{
    "code": 409,
    "message": "This capture has already been stopped"
}
```

```typescript
{
    "code": 409,
    "message": "This capture failed and is no longer running"
}
```

```typescript
{
    "code": 409,
    "message": "Cannot stop a capture until it has started completely. Try again soon."
}
```

## Edit a Capture

Edits the information of a specific capture associated with an environment.

```
PUT /api/captures/{id}
```

#### Permissions

User must be logged in. User must either be the owner of the capture or be an  admin of the environment.

#### Query Params <a href="#query-params" id="query-params"></a>

| Param        | Description               | Optional/Required |
| ------------ | ------------------------- | ----------------- |
| id=\[number] | id of the capture to edit | Required          |

#### Sample Request Body

```typescript
{
 "name" : "newName"
}
```

#### Success Response

```
200 OK
```

#### Error Response

```
400 BAD REQUEST
```

```typescript
{
    "code": 400,
    "message": "Capture with the same name already exists in this environment"
}
```

```
404 NOT FOUND
```

```typescript
{
    "code": 404,
    "message": "Capture not found"
}
```

## Post a New Capture

Creates a new capture in an environment.

```
POST /api/captures
```

#### Permissions

User must be logged in. User must be a member of the environment.

#### Body Params

| Param                  | Description                                                          | Optional/Required |
| ---------------------- | -------------------------------------------------------------------- | ----------------- |
| name=\[string]         | Name of the capture that will be displayed in the UI                 | Required          |
| envId=\[number]        | id of the environment that the capture belongs to                    | Required          |
| status=\[string]       | Status of the capture. Must be ‘SCHEDULED’, ‘STARTED’, or ‘STARTING’ | Optional          |
| start=\[date]          | Time that the capture actually started                               | Optional          |
| scheduledStart=\[date] | Time that the capture is scheduled for                               | Optional          |
| duration=\[number]     | How long the capture will run for                                    | Optional          |

#### Sample Request Body

```typescript
{
 "name" : "myCapture",
 "start" : "2018-05-19 12:00:00",
 "end" : null,
 "envId" : 1,
 "scheduledStart": null
}
```

#### Success Response

```
200 OK
```

```typescript
{
    "id": 1,
    "name": "myCapture",
    "start": "2018-05-19 12:00:00",
    "scheduledStart": null,
    "scheduledEnd": null,
    "end": null,
    "status": "STARTED",
    "envId": 1,
    "type": "CAPTURE",
    "reason": null
}
```

#### Error Response

```
400 BAD REQUEST
```

```typescript
{
    "code": 400,
    "message": "Capture with the same name already exists in this environment"
}
```

```typescript
{
    "code": 400,
    "message": "Duration must be at least 60 seconds"
}
```

```typescript
{
    "code": 400,
    "message": "Cannot schedule without a schedule start time"
}
```

## Delete a Capture

Deletes a specific capture associated with an environment.&#x20;

```
DELETE /api/captures/{id}
```

#### Permissions

User must be logged in. User must either be the owner of the capture or be an admin of the environment.

#### Query Params <a href="#query-params" id="query-params"></a>

| Param        | Description                 | Optional/Required |
| ------------ | --------------------------- | ----------------- |
| id=\[number] | id of the capture to delete | Required          |

#### Success Response

```
200 OK
```

#### Error Response

```
404 NOT FOUND
```

```typescript
{
    "code": 404,
    "message": "Capture not found"
}
```
