# /documents

## getById

<mark style="color:blue;">`GET`</mark> `URL /documents/:documentId/getById`

Recuperación de un documento

#### Path Parameters

| Name                                         | Type   | Description                                                                                             |
| -------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------- |
| documentId<mark style="color:red;">\*</mark> | string | ID del documento. Se obtiene como respuesta del método [**`sendBill`**](/api-rest/personas.md#sendbill) |

{% tabs %}
{% tab title="200: OK El status puede ser ACEPTADO, RECHAZADO o EXCEPCION" %}

```javascript
{
    "production": true,
    "status": "ACEPTADO",
    "type": "01",
    "issueTime": 1604698592, // fecha de emisión
    "responseTime": 1604698788, // fecha de respuesta SUNAT
    "fileName": "20123456789-01-F001-00000001",
    "xml": "https://...",
    "cdr": "https://...",
    "faults": [], // arreglo de errores
    "notes": [], // arreglo de observaciones
    "personaId": "5f6cd73425f5c52d375dd55c",
    "reference": "referencia enviada al momento de emitir..."
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "error": {} // objeto con datos del error
}
```

{% endtab %}
{% endtabs %}

## getAll

<mark style="color:blue;">`GET`</mark> `URL /documents/getAll?personaId=[:personaId]&personaToken=[:personaToken]&...`

Recuperación de varios documentos

#### Query Parameters

| Name                                           | Type   | Description                                                                                        |
| ---------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------- |
| personaId<mark style="color:red;">\*</mark>    | string | Identificador de tu empresa                                                                        |
| personaToken<mark style="color:red;">\*</mark> | string | Token de acceso de tu empresa                                                                      |
| limit                                          | number | Limita la cantidad de documentos retornados (max. 100)                                             |
| skip                                           | number | Salta cierta cantidad de documentos                                                                |
| from                                           | number | (desde) fecha de emisión en formato UNIX                                                           |
| to                                             | number | (hasta) fecha de emisión en formato UNIX                                                           |
| status                                         | string | Estado del documento. Puede ser **`PENDIENTE`**, **`EXCEPCION`**, **`ACEPTADO`** o **`RECHAZADO`** |
| type                                           | string | Código del tipo de documento. Puede ser `01`, `03`, `D1`, etc                                      |
| order                                          | String | Puede ser **`ASC`**, o **`DESC`**                                                                  |
| serie                                          | String | Serie del documento                                                                                |
| number                                         | String | Correlativo del documento (8 dígitos)                                                              |

{% tabs %}
{% tab title="200: OK Devuelve un array de documentos. El orden por defecto es el de creación, no el de emisión." %}

```javascript
[
    {
        "production": true,
        "status": "ACEPTADO",
        "type": "01",
        "issueTime": 1604698592, // fecha de emisión
        "responseTime": 1604698788, // fecha de respuesta SUNAT
        "fileName": "20123456789-01-F001-00000001",
        "xml": "https://...",
        "cdr": "https://...",
        "faults": [], // arreglo de errores
        "notes": [], // arreglo de observaciones
        "personaId": "5f6cd73425f5c52d375dd55c",
        "reference": "referencia enviada al momento de emitir..."
    },
    //...
]
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "error": {} // objeto con datos del error
}
```

{% endtab %}
{% endtabs %}

## getPDF

<mark style="color:blue;">`GET`</mark> `URL /documents/:documentId/getPDF/:format/:fileName[.pdf]`

Generación de la representación impresa

#### Path Parameters

| Name                                              | Type   | Description                                                                                                                                                  |
| ------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| documentId<mark style="color:red;">\*</mark>      | string | ID del documento. Se obtiene como respuesta del método [**`sendBill`**](broken://pages/-MFy5Mwam0c9tk-opY65)                                                 |
| format<mark style="color:red;">\*</mark>          | string | Actualmente puede ser **`A4`**, **`A5`**, **`ticket58mm`** o **`ticket80mm`**                                                                                |
| fileName\[.pdf]<mark style="color:red;">\*</mark> | string | <p>Nombre usado para el archivo, agregando <strong><code>.pdf</code></strong> al final.</p><p><br>Ejemplo: <code>20606170514-01-F001-00000001.pdf</code></p> |

{% tabs %}
{% tab title="200: OK " %}

```
// representación impresa del documento en formato PDF
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.apisunat.com/api-rest/documents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
