Listar citas
GET
/appointmentsRecupera una lista paginada de citas para su organización. Admite filtrado por rango de fechas, estado y paciente.
Ejemplos de código
Node.js
const fetch = require('node-fetch');
async function llamarApi() {
const claveApi = 'YOUR_API_KEY';
const from = 'su-from';
const to = 'su-to';
const status = 'su-status';
const patientId = 'su-patientId';
const rowsPerPage = 'su-rowsPerPage';
const page = 'su-page';
const sortDir = 'su-sortDir';
const queryString = new URLSearchParams({
from: from,
to: to,
status: status,
patientId: patientId,
rowsPerPage: rowsPerPage,
page: page,
sortDir: sortDir
}).toString();
const url = `https://account.lunahealth.app/api/appointments` + (queryString ? `?${queryString}` : '');
try {
const response = await fetch(url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${claveApi}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
console.log(data);
return data;
} catch (error) {
console.error('Error al llamar a la API:', error);
throw error;
}
}
llamarApi();Python
import requests
def llamarApi():
claveApi = 'YOUR_API_KEY'
url = 'https://account.lunahealth.app/api/appointments'
headers = {
'Authorization': f'Bearer {claveApi}',
'Content-Type': 'application/json'
}
params = {
'from': 'su-from',
'to': 'su-to',
'status': 'su-status',
'patientId': 'su-patientId',
'rowsPerPage': 'su-rowsPerPage',
'page': 'su-page',
'sortDir': 'su-sortDir'
}
try:
response = requests.get(
url,
headers=headers,
params=params
)
response.raise_for_status()
data = response.json()
print(data)
return data
except requests.exceptions.RequestException as e:
print(f'Error al llamar a la API: {e}')
raise
llamarApi()Parámetros
| Nombre | Ubicación | Tipo | Requerido | Descripción |
|---|---|---|---|---|
from | query | string (date-time) | No | Fecha de inicio opcional para filtrar por fecha de creación (formato ISO 8601) |
to | query | string (date-time) | No | Fecha de fin opcional para filtrar por fecha de creación (formato ISO 8601) |
status | query | string | No | Filtrar por estado |
patientId | query | string | No | ID del paciente para filtrar los resultados |
rowsPerPage | query | number | No | Número de filas por página |
page | query | number | No | Número de página (indexado en 0) |
sortDir | query | string | No | Dirección de ordenación |
Respuestas
| Estado | Descripción |
|---|---|
200 | Respuesta exitosa |
400 | Datos de entrada no válidos |
401 | Autorización no proporcionada |
403 | Acceso insuficiente |
404 | No encontrado |
500 | Error interno del servidor |
200 — Respuesta exitosa
Campos de la respuesta
| Nombre | Tipo | Requerido | Descripción |
|---|---|---|---|
items | array<object> | Sí | — |
meta | object | Sí | — |
Ejemplo de respuesta
{
"items": [
{
"id": "string",
"status": "NEW",
"type": "APPOINTMENT",
"title": "string",
"description": "string",
"start_time": "string",
"end_time": "string",
"telemedicine": true,
"created_at": "string",
"updated_at": "string",
"patient": {
"id": "string",
"first_name": "string",
"last_name": "string",
"email": "string"
},
"staffs": [
{
"id": "string",
"first_name": "string",
"last_name": "string"
}
],
"service": {
"id": "string",
"name": "string"
},
"location": {
"id": "string",
"name": "string"
}
}
],
"meta": {
"totalRowCount": 0,
"page": 0,
"rowsPerPage": 0
}
}400 — Datos de entrada no válidos
Campos de la respuesta
| Nombre | Tipo | Requerido | Descripción |
|---|---|---|---|
message | string | Sí | The error message |
code | string | Sí | The error code |
issues | array<object> | No | An array of issues that were responsible for the error |
Ejemplo de respuesta
{
"code": "BAD_REQUEST",
"message": "Invalid input data",
"issues": []
}401 — Autorización no proporcionada
Campos de la respuesta
| Nombre | Tipo | Requerido | Descripción |
|---|---|---|---|
message | string | Sí | The error message |
code | string | Sí | The error code |
issues | array<object> | No | An array of issues that were responsible for the error |
Ejemplo de respuesta
{
"code": "UNAUTHORIZED",
"message": "Authorization not provided",
"issues": []
}403 — Acceso insuficiente
Campos de la respuesta
| Nombre | Tipo | Requerido | Descripción |
|---|---|---|---|
message | string | Sí | The error message |
code | string | Sí | The error code |
issues | array<object> | No | An array of issues that were responsible for the error |
Ejemplo de respuesta
{
"code": "FORBIDDEN",
"message": "Insufficient access",
"issues": []
}404 — No encontrado
Campos de la respuesta
| Nombre | Tipo | Requerido | Descripción |
|---|---|---|---|
message | string | Sí | The error message |
code | string | Sí | The error code |
issues | array<object> | No | An array of issues that were responsible for the error |
Ejemplo de respuesta
{
"code": "NOT_FOUND",
"message": "Not found",
"issues": []
}500 — Error interno del servidor
Campos de la respuesta
| Nombre | Tipo | Requerido | Descripción |
|---|---|---|---|
message | string | Sí | The error message |
code | string | Sí | The error code |
issues | array<object> | No | An array of issues that were responsible for the error |
Ejemplo de respuesta
{
"code": "INTERNAL_SERVER_ERROR",
"message": "Internal server error",
"issues": []
}