> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.termina.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.termina.ai/_mcp/server.

# Finalize Upload

POST https://app.termina.ai/api/v1/group/{group_id}/deal/{deal_id}/file/{file_id}/finalize

Finalize a file upload after uploading to GCS via signed URL.

This endpoint should be called after the client has:
1. Called create_file_entry to get a signed URL and file ID
2. Uploaded the file directly to GCS using the signed URL

The endpoint fetches the actual file size from GCS and updates the database record.
This is necessary because signed-URL uploads bypass our server, so we don't know
the file size until we query GCS after the upload completes.

Returns:
    FileResponse: The updated file record with the correct filesize

Raises:
    404: If the file hasn't been uploaded to GCS yet (blob doesn't exist)

Reference: https://docs.termina.ai/api-reference/deal-management/file/finalize-upload

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://app.termina.ai` (Production server, default)
- `https://app.termina.dev` (Development server)
- `http://localhost:8000` (Local development server)

## Request

### Path parameters

- `group_id` (integer, required)
- `deal_id` (integer, required)
- `file_id` (integer, required)

## Response

### 200

Successful Response

- `name` (string, required) — The human-readable name of the file
- `id` (integer, required)
- `deal_id` (integer, required, nullable)
- `type` (enum, optional, nullable) — The type of the file
  - Allowed values: `deck`, `financials`, `raw_data`, `snapshot`, `full`, `mini`, `nano`, `other`
- `created_at` (string, optional)
- `updated_at` (string, optional, nullable)
- `is_archived` (boolean, optional, nullable)
- `filesize` (integer, optional, default: 0) — The size of the file in bytes

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `input` (any, optional)
- `ctx` (ValidationErrorCtx, optional)

### ValidationErrorLocItems

### ValidationErrorCtx

## Examples

**Response**

```json
{
  "name": "string",
  "id": 1,
  "deal_id": 1,
  "type": "deck",
  "created_at": "2024-01-15T09:30:00Z",
  "updated_at": "2024-01-15T09:30:00Z",
  "is_archived": true,
  "filesize": 0
}
```

**SDK Code**

```python
import requests

url = "https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize"

headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://app.termina.ai/api/v1/group/1/deal/1/file/1/finalize")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```