# Update a file

URL: https://docs.sparklayer.io/developers/api/files/update-a-file
Operation: `PATCH /api/v1/files/{id}` (operationId `updateFile`)
OpenAPI spec: https://docs.sparklayer.io/openapi/files.yaml

Returns a new signed upload URL for an existing file so you can replace its contents: upload with an HTTP `PUT` to `url`, sending the `required_headers`, within 15 minutes. No request body is needed and the file path cannot be changed. Returns `404` if the file does not exist.

`PATCH /api/v1/files/{id}`

**Base URLs:** `https://app.sparklayer.io` (Live), `https://test.app.sparklayer.io` (Test)

**Authentication:** send `Authorization: Bearer <access_token>` and `Site-Id: <site id>` with every request. Get the token from [Get an access token](https://docs.sparklayer.io/developers/api/core/get-an-access-token.md); see [Authentication](https://docs.sparklayer.io/developers/authentication.md).

### Example request

```bash
curl -X PATCH "https://app.sparklayer.io/api/v1/files/86027e2c-e853-11ee-b1d4-7c214a6ed8c7" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID"
```

Set `SPARKLAYER_TOKEN` to an access token and `SPARKLAYER_SITE_ID` to your Site ID. For the test environment, use `https://test.app.sparklayer.io`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | Yes | The file's ID. Example: `86027e2c-e853-11ee-b1d4-7c214a6ed8c7` |

### Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Site-Id` | string | Yes | Your SparkLayer Site ID, from Settings > API in the SparkLayer Dashboard. Example: `jones-climbing` |

### Responses

#### 202: A new signed upload `url` for the file. Upload with an HTTP `PUT`, sending the `required_headers`, within 15 minutes.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `file_path` | string | | The path to the file, including the file name |
| `id` | string | | The ID of this type |
| `url` | string \| null | | URL to download/upload the file. For GET, this will be a readable link. If the file is not ready, this will be `null`. For POST/PATCH this will be a writeable link |
| `required_headers` | object[] | | An array of headers you must include in the file upload/download request |
| `required_headers[].name` | string | | Name of the header |
| `required_headers[].value` | string | | Value of the header |

```json
{
  "file_path": "folder/file.png",
  "id": "86027e2c-e853-11ee-b1d4-7c214a6ed8c7",
  "url": "https://files.sparklayer.io/siteId/siteEnv/path/to/file.png.",
  "required_headers": [
    {
      "name": "Content-Type",
      "value": "application/pdf"
    }
  ]
}
```

#### Other statuses: An error. The body describes the problem: see [Errors](https://docs.sparklayer.io/developers/errors.md).

`application/problem+json`: the standard error body (below).

### Error body

Error responses with a body use this RFC 7807 problem details object. See [Errors](https://docs.sparklayer.io/developers/errors.md) for every status code and which errors to retry.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `detail` | string | | Human-readable summary of the error |
| `status` | integer | | HTTP Status code returned from API |
| `title` | string | | Machine-readable error code |
| `type` | string \| null | | |
| `errors` | object[] \| null | | A list of errors related to the call |
| `errors[].code` | string | | Machine-readable error code |
| `errors[].property` | string | | The property the error relates to |
| `errors[].message` | string | | Human readable summary of the error |

```json
{
  "detail": "Data Validation Failed",
  "status": 400,
  "title": "invalid-api-request-contents",
  "type": "https://docs.sparklayer.io/api/errors#invalid-api-request-contents",
  "errors": [
    {
      "code": "resource-not-found",
      "property": "template",
      "message": "template not found"
    }
  ]
}
```
