Luna SaludReferencia de la APILuna Salud

Create a patient

POST/patients

Registers a new patient in your organization. The patient is created inactive and scoped to your organization. Staff or administrator accounts cannot be created through this endpoint. Duplicate registrations (same email, or same name and date of birth) are rejected. Requires an API key with the write scope; keys issued before write access existed are read-only and must be regenerated by an administrator.

Ejemplos de código

Node.js

const fetch = require('node-fetch');

async function llamarApi() {
  const claveApi = 'YOUR_API_KEY';
  const url = `https://account.lunahealth.app/api/patients`;
  const requestBody = {
    // Agregue sus datos del cuerpo de la solicitud aquí
  };

  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${claveApi}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(requestBody)
    });
    
    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/patients'
    
    headers = {
        'Authorization': f'Bearer {claveApi}',
        'Content-Type': 'application/json'
    }
    
    params = {

    }
    
    # Agregue sus datos del cuerpo de la solicitud aquí
    request_body = {}
        try:
        response = requests.post(
            url,
            headers=headers,
            params=params,
            json=request_body
        )
        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()

Cuerpo de la solicitud

Requerido

Campos de la solicitud

NombreTipoRequeridoDescripción
first_namestringSí—
last_namestringSí—
phonestringNo—
emailstring (email) | stringNo—
curpstringNo—
birthdatestringNo—
genderstringNo—

Ejemplo de solicitud

{
  "first_name": "string",
  "last_name": "string",
  "phone": "string",
  "email": "user@example.com",
  "curp": "string",
  "birthdate": "string",
  "gender": "MALE"
}

Respuestas

EstadoDescripción
200Respuesta exitosa
400Datos de entrada no válidos
401Autorización no proporcionada
403Acceso insuficiente
500Error interno del servidor

200 — Respuesta exitosa

Campos de la respuesta

NombreTipoRequeridoDescripción
idstringSí—
first_namestringnullSí—
last_namestringnullSí—
emailstringnullSí—
typestring | nullNo—

Ejemplo de respuesta

{
  "id": "string",
  "first_name": null,
  "last_name": null,
  "email": null,
  "type": "STAFF"
}

400 — Datos de entrada no válidos

Campos de la respuesta

NombreTipoRequeridoDescripción
messagestringSíThe error message
codestringSíThe error code
issuesarray<object>NoAn 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

NombreTipoRequeridoDescripción
messagestringSíThe error message
codestringSíThe error code
issuesarray<object>NoAn 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

NombreTipoRequeridoDescripción
messagestringSíThe error message
codestringSíThe error code
issuesarray<object>NoAn array of issues that were responsible for the error

Ejemplo de respuesta

{
  "code": "FORBIDDEN",
  "message": "Insufficient access",
  "issues": []
}

500 — Error interno del servidor

Campos de la respuesta

NombreTipoRequeridoDescripción
messagestringSíThe error message
codestringSíThe error code
issuesarray<object>NoAn array of issues that were responsible for the error

Ejemplo de respuesta

{
  "code": "INTERNAL_SERVER_ERROR",
  "message": "Internal server error",
  "issues": []
}
Create a patient | API de Luna Health