API REST - Guía Rápida

Cómo autenticarte y consultar nuestros endpoints desde diferentes lenguajes.

Base URL

Todas las rutas REST comienzan con:

https://www.crmapi.puntoonline.net/api/v1

Autenticación

Usamos Bearer Tokens (Laravel Sanctum). Primero obtén un token registrándote o iniciando sesión.

  • Login: POST /api/v1/auth/login
  • Register: POST /api/v1/auth/register

Incluye el token en el header Authorization: Bearer <TOKEN> y añade Accept: application/json.

Ejemplos Rápidos

Reemplaza YOUR_TOKEN por tu token real.

cURL

curl -X GET "https://www.crmapi.puntoonline.net/api/v1/dashboard/metrics" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN"

JavaScript (fetch)

fetch("https://www.crmapi.puntoonline.net/api/v1/dashboard/metrics", {
  headers: {
    Accept: 'application/json',
    Authorization: 'Bearer YOUR_TOKEN'
  }
}).then(r => r.json()).then(console.log).catch(console.error);

Node.js (axios)

import axios from 'axios';
const api = axios.create({ baseURL: 'https://www.crmapi.puntoonline.net/api/v1' });
const res = await api.get('/dashboard/metrics', {
  headers: { Authorization: 'Bearer YOUR_TOKEN' }
});
console.log(res.data);

Python (requests)

import requests
url = "https://www.crmapi.puntoonline.net/api/v1/dashboard/metrics"
headers = {"Accept":"application/json","Authorization":"Bearer YOUR_TOKEN"}
r = requests.get(url, headers=headers)
print(r.status_code, r.json())

PHP (Guzzle)

$client = new \GuzzleHttp\Client(['base_uri' => 'https://www.crmapi.puntoonline.net/api/v1']);
$res = $client->get('/dashboard/metrics', [
  'headers' => [
    'Accept' => 'application/json',
    'Authorization' => 'Bearer YOUR_TOKEN',
  ],
]);
$body = json_decode($res->getBody()->getContents(), true);
print_r($body);

Errores comunes

  • 401/403: Falta el header Authorization o el token es inválido/caducado.
  • HTML en lugar de JSON: el servidor no reenvía el header Authorization a PHP o la URL no es correcta.
  • 419 CSRF: usa REST puro con Accept: application/json y sin depender de cookies de sesión.

Endpoints útiles

  • GET /api/v1/dashboard/metrics
  • GET /api/v1/dashboard/leads-chart
  • GET /api/v1/dashboard/leads-last-30
  • GET /api/v1/dashboard/opportunities-by-stage
  • GET /api/v1/dashboard/clients-by-type

Integración Contact Form (público por ApiKey)

Permite que tu sitio (WordPress, Next.js, etc.) nos envíe leads directamente al CRM. Debes incluir tu ApiKey en el header X-Api-Key. La ApiKey se gestiona desde Organizaciones. El formulario requiere nombre, email, teléfono y cédula.

Endpoint:

POST /api/v1/contact-form

Headers mínimos:

  • Content-Type: application/json
  • X-Api-Key: <TU_API_KEY>
  • Accept: application/json

Body JSON:

{
    "name": "Jane Doe",
    "email": "jane@example.com",
    "phone": "0414-1234567",
    "identification_number": "V-12345678",
    "message": "Estoy interesada en sus servicios",
    "client_type_id": 1
}

cURL

curl -X POST "https://www.crmapi.puntoonline.net/api/v1/contact-form" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "X-Api-Key: YOUR_API_KEY" \
    -d '{"name":"Jane Doe","email":"jane@example.com","phone":"0414-1234567","identification_number":"V-12345678","message":"Hola"}'

JavaScript (fetch)

await fetch("https://www.crmapi.puntoonline.net/api/v1/contact-form", {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'X-Api-Key': 'YOUR_API_KEY'
    },
    body: JSON.stringify({ name: 'Jane Doe', email: 'jane@example.com', phone: '0414-1234567', identification_number: 'V-12345678', message: 'Hola' })
}).then(r => r.json()).then(console.log);

Python (requests)

import requests
url = "https://www.crmapi.puntoonline.net/api/v1/contact-form"
headers = {"Content-Type":"application/json","Accept":"application/json","X-Api-Key":"YOUR_API_KEY"}
data = {"name":"Jane Doe","email":"jane@example.com","phone":"0414-1234567","identification_number":"V-12345678","message":"Hola"}
r = requests.post(url, json=data, headers=headers)
print(r.status_code, r.json())

PHP (Guzzle)

$client = new \GuzzleHttp\Client(['base_uri' => 'https://www.crmapi.puntoonline.net/api/v1']);
$res = $client->post('/contact-form', [
    'headers' => [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
        'X-Api-Key' => 'YOUR_API_KEY',
    ],
    'json' => [ 'name' => 'Jane Doe', 'email' => 'jane@example.com', 'phone' => '0414-1234567', 'identification_number' => 'V-12345678', 'message' => 'Hola' ]
]);
echo $res->getStatusCode();

Respuesta 201:

{
    "status": "success",
    "message": "Formulario recibido correctamente",
    "client": {
        "id": 123,
        "name": "Jane Doe",
        "email": "jane@example.com"
    },
    "organization": {
        "id": 5,
        "name": "Mi Organización"
    }
}