Skip to main content

Introducción

En esta guía vas a aprender cómo hacer tu primera integración con la API de La Pyme. Al final, vas a poder obtener la lista de clientes de tu organización programáticamente.
Prerequisitos: Necesitás tener una cuenta activa en La Pyme y acceso al Dashboard para generar API keys.

Paso 1: Obtener tu API Key

Crear un API Key

  1. Iniciá sesión en el Dashboard de La Pyme
  2. Navegá a ConfiguraciónIntegracionesAPI Keys
  3. Hacé click en Crear nuevo API Key
  4. Configurá los permisos:
    • Para esta guía, seleccioná customers:read
    • Dale un nombre descriptivo como “Mi primera integración”
  5. Hacé click en Generar
  6. Copiá el API key inmediatamente y guardalo en un lugar seguro
El API key solo se muestra una vez. Si lo perdés, vas a tener que crear uno nuevo.

Paso 2: Verificar la Conexión

Antes de empezar, verificá que la API esté funcionando con el endpoint de health check:
curl -X GET "https://api.lapyme.com.ar/health"
Deberías recibir una response como esta:
{
  "status": "healthy",
  "timestamp": "2024-01-15T10:30:00Z",
  "version": "1.0.0",
  "uptime": 86400,
  "environment": "production"
}

Paso 3: Tu Primera Request Autenticada

Ahora vamos a obtener la lista de clientes usando tu API key:
curl -X GET "https://api.lapyme.com.ar/api/v1/customers" \
  -H "Authorization: Bearer TU_API_KEY_AQUI" \
  -H "Content-Type: application/json"

Response Esperada

Si todo está configurado correctamente, vas a recibir algo así:
{
  "success": true,
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Juan Pérez",
      "email": "[email protected]",
      "phone": "+54 11 1234-5678",
      "taxId": "20-12345678-9",
      "taxIdType": "CUIT",
      "isActive": true,
      "createdAt": "2024-01-10T10:00:00Z",
      "updatedAt": "2024-01-10T10:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 50,
    "total": 1,
    "totalPages": 1
  }
}

Paso 4: Filtrar y Paginar Resultados

La API soporta filtros y paginación. Probá estos ejemplos:

Buscar Clientes

curl -X GET "https://api.lapyme.com.ar/api/v1/customers?search=Juan" \
  -H "Authorization: Bearer TU_API_KEY_AQUI"

Pagination

curl -X GET "https://api.lapyme.com.ar/api/v1/customers?page=1&limit=10" \
  -H "Authorization: Bearer TU_API_KEY_AQUI"

Paso 5: Explorar Productos

Con el mismo API key, también podés acceder a los productos:
curl -X GET "https://api.lapyme.com.ar/api/v1/products" \
  -H "Authorization: Bearer TU_API_KEY_AQUI"

Filtrar Productos

Los productos soportan filtros adicionales:
# Por tipo de producto
curl -X GET "https://api.lapyme.com.ar/api/v1/products?productType=product" \
  -H "Authorization: Bearer TU_API_KEY_AQUI"

# Por estado activo
curl -X GET "https://api.lapyme.com.ar/api/v1/products?isActive=true" \
  -H "Authorization: Bearer TU_API_KEY_AQUI"

# Combinando filtros
curl -X GET "https://api.lapyme.com.ar/api/v1/products?search=laptop&productType=product&isActive=true" \
  -H "Authorization: Bearer TU_API_KEY_AQUI"

Response de Productos

Una respuesta típica de productos incluye información detallada como categoría, precios y proveedor:
{
  "success": true,
  "data": [
    {
      "id": "b383e3ae-bd24-4c05-86a4-f338ac60d006",
      "name": "Almohada De Espuma Rectangular 70x40 Tradicional Polipluma",
      "description": "Almohada De Espuma Rectangular 70x40 Tradicional Polipluma",
      "category": {
        "id": "7dbc3112-00d5-4062-94f5-d8cdba9361a6",
        "name": "MercadoLibre"
      },
      "sku": "MLA910480365",
      "barcode": "1234567890123",
      "oemCode": null,
      "currency": "PES",
      "cost": 100000,
      "price": 200000,
      "taxRate": {
        "id": 5,
        "value": 21
      },
      "stockMinimum": 0,
      "defaultSupplier": null,
      "productType": "product",
      "isActive": true,
      "organizationSlug": "rohi-sommiers",
      "createdAt": "2025-08-23T19:58:01.847Z",
      "updatedAt": "2025-08-30T01:08:59.827Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 1,
    "total": 8,
    "totalPages": 8
  }
}

Manejo de Errores

Siempre revisá el campo success en la response para detectar errores:
const response = await fetch('https://api.lapyme.com.ar/api/v1/customers', {
  headers: {
    'Authorization': `Bearer ${apiKey}`
  }
});

const data = await response.json();

if (!data.success) {
  console.error('Error:', data.error);
  console.error('Código:', data.code);
  // Manejar el error según tu aplicación
} else {
  console.log('Clientes:', data.data);
}

Errores Comunes

ErrorCausaSolución
MISSING_API_KEYNo incluiste el header AuthorizationAgregá el header con tu API key
INVALID_API_KEYAPI key incorrecto o expiradoVerificá tu API key en el Dashboard
INSUFFICIENT_SCOPENo tenés permisos para ese endpointActualizá los scopes de tu API key
VALIDATION_ERRORParámetros inválidosRevisá los parámetros de tu request

Próximos Pasos

¡Felicitaciones! Ya sabés cómo usar la API de La Pyme. Ahora podés:
  1. Explorar todos los endpoints en la referencia de API
  2. Leer sobre autenticación avanzada en la guía de autenticación
  3. Implementar tu integración usando los ejemplos de código
  4. Contactar soporte si necesitás ayuda en [email protected]

Ejemplos Completos

Script de Node.js Completo

// api-client.js
const API_KEY = process.env.LAPYME_API_KEY;
const BASE_URL = 'https://api.lapyme.com.ar';

async function apiRequest(endpoint, options = {}) {
  const response = await fetch(`${BASE_URL}${endpoint}`, {
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json',
      ...options.headers
    },
    ...options
  });
  
  const data = await response.json();
  
  if (!data.success) {
    throw new Error(`API Error: ${data.error} (${data.code})`);
  }
  
  return data;
}

async function getCustomers(search = '', page = 1, limit = 50) {
  const params = new URLSearchParams({
    search,
    page: page.toString(),
    limit: limit.toString()
  });
  
  return apiRequest(`/api/v1/customers?${params}`);
}

async function getProducts(filters = {}) {
  const params = new URLSearchParams();
  
  Object.keys(filters).forEach(key => {
    if (filters[key] !== undefined) {
      params.append(key, filters[key].toString());
    }
  });
  
  return apiRequest(`/api/v1/products?${params}`);
}

// Ejemplo de uso
async function main() {
  try {
    // Obtener todos los clientes
    const customers = await getCustomers();
    console.log(`Total de clientes: ${customers.pagination.total}`);
    
    // Buscar productos activos
    const products = await getProducts({ 
      isActive: true, 
      productType: 'product' 
    });
    console.log(`Productos encontrados: ${products.data.length}`);
    
  } catch (error) {
    console.error('Error:', error.message);
  }
}

main();
Para ejecutar este script:
# Instalá las dependencias (si usás Node.js < 18)
npm install node-fetch

# Configurá tu API key
export LAPYME_API_KEY="tu_api_key_aqui"

# Ejecutá el script
node api-client.js