> For the complete documentation index, see [llms.txt](https://docs.insurehero.io/shield-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.insurehero.io/shield-api/claims/claims-management/claims-asset-management.md).

# Claims Asset Management

With the InsureHero Shield API you can upload assets in behalf of your claims. This creates a repository of assets for each claim.

{% hint style="success" %}
**Good to know**

Attaching assets to entities like claims & events is a 2 step process.

* First assets are uploaded to a private repository. A public URL is returned for each of the uploaded assets.
* Then you create/update an entity with the given URLs.
  {% endhint %}

## Endpoints

<table><thead><tr><th width="113">Method</th><th>Endpoint</th></tr></thead><tbody><tr><td><mark style="color:green;">POST</mark></td><td><a href="#upload-assets"><code>https://app.insurehero.io/api/shield/v1/claims/:claimId/assets</code></a></td></tr><tr><td><mark style="color:green;">POST</mark></td><td><a href="#upload-assets"><code>https://app.insurehero.io/api/shield/v2/claims/:claimId/assets</code></a></td></tr></tbody></table>

### Upload assets

When needed allow users to upload assets to their private repositories.

## Upload assets to a claim

{% tabs %}
{% tab title="v1" %} <mark style="color:green;">`POST`</mark> `https://app.insurehero.io/api/shield/v1/claims/:claimId/assets`
{% endtab %}

{% tab title="v2" %} <mark style="color:green;">`POST`</mark> `https://app.insurehero.io/api/shield/v2/claims/:claimId/assets`
{% endtab %}
{% endtabs %}

Both versions work the same way.

When you need to add documents, videos or any other type of asset to backup a claim or attach evidence to a risk item event, you will first need to upload those assets to the claim. Files that are uploaded successfully are also added to the claim's `assets` as `{ "url", "name" }`.

#### Path Parameters

| Name                                      | Type | Description             |
| ----------------------------------------- | ---- | ----------------------- |
| claimId<mark style="color:red;">\*</mark> | uuid | The id of a given claim |

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |
| Content-Type<mark style="color:red;">\*</mark>  | string | multipart/form-data |

#### Request Body

The body is sent as `multipart/form-data`.

| Name                                    | Type    | Description                                                                                                                                                        |
| --------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| files<mark style="color:red;">\*</mark> | Blob\[] | The list of files to be uploaded. Use the `files` key once per file.                                                                                               |
| name                                    | string  | Provides descriptive context for the files being uploaded. It is applied to every file of the request. If you do not provide a name, the name of each file is used |

{% tabs %}
{% tab title="200: OK Upload finished" %}
Each file will be returned with a success or fail status and a public URL in the case of a success.

```json
{
    "data": {
        "result": "1 / 2 files uploaded successfully.",
        "files": [
            {
                "success": true,
                "url": "https://storage.example.com/claims/0ccad1d6-18ee-5c17-a684-9f8fe203d7c1/d7eec8ed-0d68-5f5f-b495-32d7c97f507b/document.pdf",
                "fileName": "document.pdf"
            },
            {
                "success": false,
                "url": null,
                "fileName": "..",
                "cause": "Invalid file name"
            }
        ]
    }
}
```

{% endtab %}

{% tab title="400: Bad Request Request contains malformed data" %}

{% endtab %}

{% tab title="401: Unauthorized Invalid or expired access token" %}

{% endtab %}

{% tab title="422: Unprocessable Entity Internal validation failed" %}
Most errors of this endpoint return the reason in `error` and `details: null`. For example, when the claim does not exist in your channel:

```json
{
    "error": "Invalid request, claimDataId does not exist for this channel_id.",
    "details": null
}
```

Other messages with the same shape:

* `"Invalid request, use the 'files' key on the form-data files that should be uploaded."`: the request has no `files`.
* `"Invalid request, not files to upload."`: the body is not valid `multipart/form-data`.

When none of the files could be uploaded, `details` contains the result of each file:

```json
{
    "error": "Invalid request, no files were uploaded.",
    "details": {
        "result": "0 / 1 files uploaded successfully.",
        "files": [
            {
                "success": false,
                "url": null,
                "fileName": "..",
                "cause": "Invalid file name"
            }
        ]
    }
}
```

If the claim could not be read or updated because of an internal error, the response has `error` `"Internal validation failed"` and `details` with `"message": "Internal error"` and an `event_id` that identifies the incident for support. See [Error Handling](https://docs.insurehero.io/shield-api/data-dictionary#error-handling).
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Keep in mind**

* Each file is uploaded independently. A file that the storage rejects is returned with `success: false` and the `cause`, and the other files are still uploaded.
* A file name that is empty after removing `/`, `\` and `..` is rejected with the cause `"Invalid file name"`.
  {% endhint %}
