# Postman

## **¿Qué es Postman?**

Postman es una plataforma popular para explorar, probar y automatizar APIs REST. Permite crear colecciones de peticiones, gestionar variables y visualizar respuestas de forma intuitiva.

**Instalación**

* Sigue la guía de instalación de Postman en la Instalación y Configuración Inicial
* Alternativamente, en macOS puedes instalarlo con Homebrew:

  <pre class="language-bash" data-title="bash" data-overflow="wrap"><code class="lang-bash">brew install --cask postman
  </code></pre>

***

## Autenticación y variables en Postman <a href="#id-3-autenticacin-y-variables-en-postman" id="id-3-autenticacin-y-variables-en-postman"></a>

**Autenticación en InfluxDB 2.x**

Toda petición a la API de InfluxDB 2.x requiere un token de autenticación. Este token debe incluirse en la cabecera HTTP `Authorization` con el formato:

{% code title="text" overflow="wrap" %}

```
Authorization: Token <INFLUX_API_TOKEN>
```

{% endcode %}

**Configuración de variables en Postman**

Para facilitar el trabajo y la reutilización de peticiones, es recomendable usar variables en la colección de Postman, tales como:

* `base_url` (ejemplo: [http://localhost:8086](http://localhost:8086/))
* `org` (nombre de la organización)
* `bucket` (nombre del bucket)
* `token` (tu API token)

Estas variables se configuran en la pestaña "Variables" de la colección.

***

## Ejecución de consultas a InfluxDB desde Postman <a href="#id-4-ejecucin-de-consultas-a-influxdb-desde-postman" id="id-4-ejecucin-de-consultas-a-influxdb-desde-postman"></a>

### Configuración inicial

1. Crea un workspace en Postman.
2. Crea una colección.
3. Configura las variables (`base_url`, `org`, `bucket`, `token`).

### Ejemplo: Consulta de datos (Flux)

* Método: POST
* URL: `{{base_url}}/api/v2/query?org={{org}}`
* Headers:
  * `Authorization: Token {{token}}`
  * `Content-Type: application/vnd.flux`
* Body (raw, tipo texto):

  <pre data-title="text" data-overflow="wrap"><code>from(bucket: "{{bucket}}")
    |> range(start: -1h)
    |> filter(fn: (r) => r._measurement == "mediciones_sensores")
  </code></pre>

Al enviar esta petición, recibirás los datos filtrados por la consulta Flux especificada.

### Ejemplo: Escritura de datos (Write)

* Método: POST
* URL: `{{base_url}}/api/v2/write?bucket={{bucket}}&org={{org}}&precision=s`
* Headers:
  * `Authorization: Token {{token}}`
  * `Content-Type: text/plain`
* Body (raw, tipo texto):

  <pre data-title="text" data-overflow="wrap"><code>temperatura,sensor_id=sensor01 temperatura=23.5 1622471127
  </code></pre>

Un código de estado 204 indica éxito en la escritura.


---

# 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://darioaplicano.gitbook.io/influxdb2.x/sesion-3/guion-de-la-sesion/documentacion/integracion-de-influxdb-con-apis-y-herramientas-externas/postman.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.
