# Request Piece Shredding

> `POST /pieces/{piece_id}/disposal`

Web page: https://reference.earthclassmail.com/v1/rest-api/spec/operations/requestpieceshredding/

URL: `POST https://api.earthclassmail.com/v1/pieces/{piece_id}/disposal`

Requests that a piece be shredded. Since shredding requires human action, the piece is not shredded immediately. The expected shredding time is included in the response payload.

Physical pieces are always shredded. The request body must be a JSON object; an empty object (`{}`) is accepted.

Returns `409` if the piece is no longer active or another operation is already in progress for it.

## Authorization

Send your API key in the `x-api-key` header.

## Parameters

| Name | In | Required | Type | Description |
| --- | --- | --- | --- | --- |
| `piece_id` | path | yes | string |  |

## Request body

Required.

Content type: `application/json`

Type: `PieceDisposalRequest`

Example — Shred and delete scans:

```json
{
  "delete_scans": true
}
```

Example — Shred and keep scans:

```json
{
  "delete_scans": false
}
```

## Responses

### 200

Success

Content type: `application/json`

Type: `PieceDisposal`

Example:

```json
{
  "id": 100001,
  "created_at": "2018-05-21T13:57:09Z",
  "updated_at": "2018-05-21T13:57:09Z",
  "operation_action": "shred",
  "tags": [],
  "piece_id": 293086,
  "estimated_completed_at": "2018-05-24T13:57:09Z",
  "completed_at": null,
  "delete_scans": true,
  "piece": null
}
```

### 401

The `x-api-key` header is missing or the key is not valid, or the caller can't access an ID in the request. IDs that don't exist return the same response as IDs the caller can't access.

Content type: `application/json`

Type: `Error`

Example — Missing API key:

```json
{
  "error": {
    "code": 401,
    "message": "The request does not include a valid access token. Please provide a valid access token.",
    "type": "Authorization"
  }
}
```

Example — Invalid API key:

```json
{
  "error": {
    "code": 401,
    "message": "x-api-key: x-api-key is invalid",
    "type": "REST"
  }
}
```

Example — No access to resource:

```json
{
  "error": {
    "code": 401,
    "message": "User does not have access to requested resource.",
    "type": "Authorization"
  }
}
```

### 403

Actions are blocked for a piece in the request. When an account's mail actions are blocked, for example because the account wasn't reverified or an identity document expired, pieces received after that can't be changed. These pieces have `actions-blocked-no-reverification` or `actions-blocked-document-expired` in their `attributes`.

Content type: `application/json`

Type: `Error`

Example — Piece actions blocked:

```json
{
  "error": {
    "code": 403,
    "message": "piece: Mail actions for piece with ID 123456 has been blocked.",
    "type": "REST"
  }
}
```

### 404

The referenced resource is accessible, but the requested item does not exist, for example a pending operation. IDs the caller can't access, or that don't exist at all, return `401` instead.

Content type: `application/json`

Type: `Error`

Example:

```json
{
  "error": {
    "code": 404,
    "message": "piece_id: Piece with ID 14460059 does not have outstanding Operation of type Recycle.",
    "type": "REST"
  }
}
```

### 409

The request conflicts with the current state of the resource.

Content type: `application/json`

Type: `Error`

### 422

The request body failed validation. The message names the invalid field.

Content type: `application/json`

Type: `Error`

Example:

```json
{
  "error": {
    "code": 422,
    "message": "label: must have a value",
    "type": "REST",
    "fields": {}
  }
}
```

## Schemas

### Error

Error envelope returned with 4xx and 5xx responses.

- `error` (object)
  - `code` (integer): Usually the HTTP status code. It can differ; a request to an unknown path returns HTTP 400 with code 500.
  - `message` (string): Human-readable description of the error.
  - `type` (string): The kind of error, for example `Authorization` or `REST`.
  - `fields` (object): Returned only with `422` responses. It may give more details about what failed validation, as lists of messages keyed by the name of the input.

### PieceDisposal

- `id` (integer)
- `created_at` (string<date-time>)
- `updated_at` (string<date-time>)
- `operation_action` (string)
- `tags` (array of string)
- `piece_id` (integer)
- `estimated_completed_at` (string<date-time> or null)
- `completed_at` (string<date-time> or null)
- `delete_scans` (boolean or null)
- `piece` (`Piece` or null)

### PieceDisposalRequest

- `delete_scans` (boolean): When `true`, the piece's digital scans are deleted along with the physical piece. When `false`, they are kept. When omitted, existing scans are kept.

### Piece

- `id` (integer)
- `created_at` (string<date-time>)
- `updated_at` (string<date-time>)
- `inbox_id` (integer)
- `barcode` (string)
- `license_plate` (integer)
- `recipient` (`PieceRecipient`)
- `mailbox_folder_id` (integer)
- `tags` (array of string)
- `attributes` (array of string)
- `sender` (`PieceSender` or null)
- `received_at` (string<date-time>)
- `date_arrived_in_mailbox` (string<date-time>)
- `weight_in_ounces` (number)
- `facility_name` (string)
- `page_count_estimate` (integer)
- `page_count_actual` (integer or null)
- `height_in_inches` (number)
- `depth_in_inches` (number)
- `length_in_inches` (number)
- `carrier` (`PieceCarrier`)
- `media` (array of `PieceMedia`)
- `ocr_data` (string)
- `envelope_ocr_data` (string)
- `piece_type` (string)
- `piece_sub_type` (string)
- `insights` (array of `PieceInsight`)
- `user_defined_tags` (array of `Tag`)
- `matched_by` (array of string)
- `operation_action` (string or null)
- `end_user_operation_status` (string or null)
- `storage_fee_amount_in_cents` (integer)
- `can_delete_scan_only` (boolean)
- `available_actions` (array of string)
- `name` (string)
- `detected_checks_count` (integer or null)
- `recipient_type` (string)

### PieceCarrier

- `name` (string)
- `class` (string)

### PieceInsight

- `type` (string)
- `confidence` (number)

### PieceMedia

- `id` (string)
- `url` (string)
- `content_type` (string)
- `tags` (array of string)
- `url_valid_until` (string<date-time>)
- `file_size_in_bytes` (integer)
- `piece_id` (integer or null)
- `scan_id` (integer or null)
- `page_count` (integer or null)
- `sequence_number` (integer or null)

### PieceRecipient

- `id` (integer)
- `name` (string)
- `inbox_id` (integer or null)
- `type` (string)

### PieceSender

- `name` (string)
- `address` (string)

### Tag

- `id` (integer)
- `created_at` (string<date-time>)
- `updated_at` (string<date-time>)
- `label` (string)
- `parent_tag_id` (integer or null)
- `piece_counts` (integer or null)
