# readDocument()

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/tools/read-document/
Language: pt

`api.tools.readDocument(sourceId) → Promise<IaGenifyFile>`

Lee uno dei files del conto indietro, contenuto incluso. Libera, e la stessa chiamata come api.files.get().

Status: GET /api/files/:id · free · content included

## Parâmetros {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `sourceId` | string | obrigatório | L'identificator da [listDocuments()](/pt/sdk/ref/tools/list-documents) o da un salva. Mancando leva imediatamente. |

```javascript
const [first] = await api.tools.listDocuments();
const file = await api.tools.readDocument(first.id);

console.log(file.name, file.mimeType);
console.log(file.content);              // a string for text, a Buffer otherwise
```

## Ce torna {#returns}

Un [IaGenifyFile](/pt/sdk/ref/files) — il medesimo objeto `api.files.create()` ti manda, ya portando il suo `sourceId`. Quindi ler, cambiare e riporlo è tre righe.

```javascript
const file = await api.tools.readDocument(id);
file.content = `${file.content}\n\nReviewed on ${new Date().toISOString().slice(0, 10)}.`;
await file.update();                    // replaces it, same sourceId
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `name` | string |  | Nome del dossier. |
| `content` | string | Buffer |  | Texte come una string; qualquer altra cosa como un Buffer. |
| `mimeType` | string |  | Coma quels fuse salvat. |
| `sourceId` | string |  | Ya set — `update()` funcionà istanzion. |
| `location · metadata` | object |  | Onde vive, e che cosa è registrat al suo sobre. |

## Como un utensilio, il cadèn a un sentiero tambèn {#as-a-tool}

> **Un parametro, due tipos de valore**
>
> Dichiarat a un model, il parametro è chiamato documente e accetta o un id o un perit sul computer del caller. Un id è tentat prima; a sfascia, il perit è let a la macchina attraverso il pacchetto. Un utensiliu per ambeds lati, perché un model non deve saper che sta sostenendo.

Un file binario letçâ di quel modo è reportat come binario e non restituit como una stringa disgregada — al modele è dito il nome, il tipo e il tamaño, e poten a chiedere una conversione in lugar.

## Erros {#errors}

| Código | Status | Quando |
| --- | --- | --- |
| file_not_found | 404 | Nessuna tal file su este cont. |
| file_missing_on_disk | 404 | Il record è là e i bytes non lo sono. |

Un appello con no `sourceId` lance prima di ogni richiesta: è un erro nel vostro codice, non una risposta da plataforma.

- [api.files.get()](/pt/sdk/ref/files/get): La stessa chiamata sul recurso de files.
- [L'agente let](/pt/sdk/agent/tools/read): Lo que un agente local vee — documenti, immagini, audio e video.
- [api.tools](/pt/sdk/ref/tools): I quinze, e i due modi di usarli.

```python
first = api.tools.list_documents()["account"][0]
file = api.tools.read_document(first["id"])

print(file.name, file.mime_type)
print(file.content)              # a str for text, bytes otherwise
```

```python
from datetime import date

file = api.tools.read_document(source_id)
file.content = f"{file.content}\n\nReviewed on {date.today().isoformat()}."
file.update()                    # replaces it, same source_id
```
