API con ejemplos reales (cURL + JS + PHP)
cURL: listar clientes con paginación
curl -s "https://tu-crm.nexgestion.es/api/v1/clients?page=1&per_page=20" \
-H "X-API-Key: crm_live_xxx"
cURL: actualizar cliente
curl -s -X PATCH https://tu-crm.nexgestion.es/api/v1/clients/123 \
-H "Authorization: Bearer crm_live_xxx" \
-H "Content-Type: application/json" \
-d '{"phone":"+34 611111111"}'
JavaScript (fetch)
const apiKey = 'crm_live_xxx';
const base = 'https://tu-crm.nexgestion.es/api/v1';
const res = await fetch(`${base}/prospects`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Lead Demo',
email: '[email protected]',
status: 'nuevo'
})
});
const data = await res.json();
console.log(data);
PHP (file_get_contents)
<?php
$apiKey = 'crm_live_xxx';
$url = 'https://tu-crm.nexgestion.es/api/v1/notes';
$payload = json_encode([
'entity_type' => 'client',
'entity_id' => 123,
'title' => 'Llamada inicial',
'content' => 'Cliente solicita propuesta.'
]);
$opts = [
'http' => [
'method' => 'POST',
'header' => "Authorization: Bearer {$apiKey}\r\nContent-Type: application/json\r\n",
'content' => $payload
]
];
$result = file_get_contents($url, false, stream_context_create($opts));
echo $result;
Scopes (resumen práctico)
- Cada recurso exige permisos propios, p.ej:
clients:read, clients:write
prospects:read, prospects:write
webhooks:read, webhooks:write
- Si falla con
403, revisa scopes de esa API key.