← Guides
Crear leads desde un formulario web
Captura leads de los formularios de tu sitio y créalos automáticamente en el CRM.
Requisitos previos
- Un Service Account (Client ID + Client Secret)
- Un formulario web en tu sitio
Paso 1: Autenticar
Obtén un Bearer token con las credenciales de tu Service Account:
cURL
curl -X POST https://magnetcustomer.net/realms/platform/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id=YOUR_ID&client_secret=YOUR_SECRET"Paso 2: Crear el lead
Envía los datos del formulario al endpoint de leads:
cURL
curl -X POST https://minha-empresa.platform-api.magnetcustomer.com/api/leads \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"fullname": "Maria Santos",
"email": "maria@exemplo.com.br",
"phones": [{ "number": "11999990000", "typePhone": "cellphone", "ddi": "+55" }],
"customFields": [
{ "customField": "FIELD_ID", "k": "origem", "v": "website" }
]
}'Paso 3: Tratar la respuesta
Si todo sale bien, la API devuelve HTTP 201 con el lead creado:
Response 201
{
"_id": "507f1f77bcf86cd799439044",
"lifeCycle": "lead",
"fullname": "Maria Santos",
"email": "maria@exemplo.com.br",
"phones": [{ "number": "11999990000", "typePhone": "cellphone", "ddi": "+55" }],
"createdAt": "2026-01-17T09:00:00Z"
}Ejemplo con el SDK de Node.js
Usa el SDK oficial para integrarlo con un handler de formulario en Express.js:
Node.js
import { MagnetCustomer } from '@magnetcustomer/sdk';
const crm = new MagnetCustomer({
account: 'minha-empresa',
clientId: process.env.MAGNET_CLIENT_ID,
clientSecret: process.env.MAGNET_CLIENT_SECRET,
});
// On form submit
app.post('/webhook/form', async (req, res) => {
const { data: lead } = await crm.leads.createLead({
contactInput: {
fullname: req.body.name,
email: req.body.email,
phones: [{ number: req.body.phone, typePhone: 'cellphone', ddi: '+55' }],
},
});
res.json({ success: true, leadId: lead._id });
});Siguiente: Aprende a configurar webhooks para recibir un aviso cuando se crean leads.