# Insertar formulario

Para insertar un formulario en Persat, se debe enviar un POST como el que se especifica a continuación.

<mark style="color:green;">`POST`</mark> `https://api.persat.com.ar/v1/digital-forms`

#### Headers

| Name                                            | Type   | Description      |
| ----------------------------------------------- | ------ | ---------------- |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer API\_KEY  |
| Content-Type<mark style="color:red;">\*</mark>  | String | application/json |

#### Request Body

| Name                                                  | Type   | Description                                              |
| ----------------------------------------------------- | ------ | -------------------------------------------------------- |
| uid\_client<mark style="color:red;">\*</mark>         | String | Identificador del cliente                                |
| df\_data.schema\_id<mark style="color:red;">\*</mark> | Number | Identificador de la plantilla del formulario             |
| df\_data.formvalues<mark style="color:red;">\*</mark> | Object | Cada uno de los valores para cada wiidget del formulario |

{% tabs %}
{% tab title="200: OK La consulta se ejecutó con éxito" %}

```json
{
    "success": true,
    "data": {
        "_id": "552",
        "created": "2022-05-19T09:26:26.000Z",
        "created_by_user_name": "Creado por Api",
        "created_by_user_id": -1,
        "client": {
            "id": 12796,
            "name": "Logistica Hnos.",
            "uid_client": "AABC9098"
        },
        "df_data": {
            "schema_id": 150,
            "results": {
                "last_updated": "2022-05-19T09:26:26.000Z",
                "formvalues": {
                    "FWA3VCpeS": "Visitado por la mañana",
                    "FWWucoyGH": 321.11,
                }
            }
        },
        "state": {
            "color": "BLUE",
            "deleted": false,
            "id": 26,
            "name": "Listo"
        },
    }
}
```

{% endtab %}

{% tab title="400: Bad Request Error en alguno de los campos enviados. userMessage contiene informacipon adicional." %}

```json
{
    "success": false,
    "error": {
        "status": 400,
        "type": "BAD_REQUEST",
        "userMessage": "'uid_client' debe ser un string"
    }
}
```

{% endtab %}
{% endtabs %}

### Ejemplo de request

En este ejemplo insertamos un formulario de tipo 150 (schema\_id) en el cliente "AABC9098". Este formulario es sencilllo ya que tiene un widget de CAMPO NUMERO y otro de CAMPO TEXTO. Ver seccion [Tipos de Widgets](/modulos/formularios-digitales/tipos-de-widgets.md) para mas detalles.

#### body

```json
{
    "uid_client": "AABC9098",
    "df_data": {
        "schema_id": 150, 
        "formvalues": {
            "FWA3VCpeS": "Visitado por la mañana",
            "FWWucoyGH": 321.11
        }
    }
}
```

### Analizando la Respuesta

En caso que no haya ningun error, obtenemos una respuesta de este estilo. La explicación de cada uno de los campos se puede ver en la sección [Obtener Formulario](/modulos/formularios-digitales/obtener-formulario.md)

{% hint style="info" %}
Cuando se inserta un formulario se agrega el estado inicial.
{% endhint %}

```json
{
    "success": true,
    "data": {
        "_id": "552",
        "created": "2022-05-19T09:26:26.000Z",
        "created_by_user_name": "Creado por Api",
        "created_by_user_id": -1,
        "client": {
            "id": 12796,
            "name": "Logistica Hnos.",
            "uid_client": "AABC9098"
        },
        "df_data": {
            "schema_id": 150,
            "results": {
                "last_updated": "2022-05-19T09:26:26.000Z",
                "formvalues": {
                    "FWA3VCpeS": "Visitado por la mañana",
                    "FWWucoyGH": 321.11
                }
            }
        },
        "state": {
             "color": "RED",
             "deleted": false,
             "id": 27,
             "name": "Cancelado"
        }
    }
}
```


---

# 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.api.persat.com.ar/modulos/formularios-digitales/insertar-formulario.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.
