> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wegluu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Paginación

> Cómo recorrer listas largas con cursores.

Las listas (`GET /conversations`, `GET /conversations/{id}/messages` y `GET /contacts`) devuelven una página a la
vez, del más nuevo al más viejo:

```json theme={null}
{
  "data": [ { "id": "…" }, { "id": "…" } ],
  "paging": { "next": "WyIyMDI2LTEyLTA1VDE1OjAyOjExLjAwMFoiLCIwMTkzYTFjNy1mM2ExLTdlOTAtYTJiNC01ZDZjOGUxZjNhMjciXQ" }
}
```

| Parámetro | Qué hace |
| - | - |
| `limit` | Cuántos elementos trae la página: de 1 a 100. Por defecto, 20 |
| `after` | El `paging.next` de la página anterior, para traer la siguiente (más vieja) |

`paging.next` es `null` en la última página.

```bash theme={null}
# Primera página
curl "https://api.wegluu.com/v1/conversations?limit=50" \
  -H "Authorization: Bearer $GLUU_API_KEY"

# Siguiente página
curl "https://api.wegluu.com/v1/conversations?limit=50&after=WyIyMDI2LTEy…" \
  -H "Authorization: Bearer $GLUU_API_KEY"
```

```javascript Node.js theme={null}
async function* allConversations() {
  let after = null;
  do {
    const url = new URL("https://api.wegluu.com/v1/conversations");
    url.searchParams.set("limit", "100");
    if (after) url.searchParams.set("after", after);
    const response = await fetch(url, { headers: { Authorization: `Bearer ${process.env.GLUU_API_KEY}` } });
    const page = await response.json();
    yield* page.data;
    after = page.paging.next;
  } while (after);
}
```

## Orden

| Lista | Ordenada por |
| - | - |
| Conversaciones | Última actividad (`updated_at`): la que tuvo un mensaje o un cambio más reciente va primero |
| Historial de una conversación | Momento del mensaje (`timestamp`): el más nuevo primero |
| Contactos | Última modificación (`updated_at`) |

Para mostrar un chat de arriba hacia abajo, invierte cada página del historial.

## Reglas del cursor

* El cursor es opaco: no lo armes ni lo modifiques. Si está mal formado, la API responde `422 invalid_cursor`.
* Usa el cursor con los mismos filtros con que pediste la primera página.
* Un cursor no vence, pero marca una posición: si entre dos páginas una conversación tiene un mensaje nuevo,
  sube al principio de la lista y no aparece en las páginas siguientes. Para sincronizar cambios, usa
  `updated_since` (ver [Tu propio inbox](https://docs.wegluu.com/guides/inbox.md#sincronizar-cambios-de-las-conversaciones)).
* Los mensajes programados desde Gluu no aparecen en el historial hasta que salen.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.