← Guides
Create Leads from Web Forms
Capture leads from your website forms and automatically create them in the CRM.
Prerequisites
- A Service Account (Client ID + Client Secret)
- A web form on your website
Step 1: Authenticate
Obtain a Bearer token using your Service Account credentials:
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"Step 2: Create the lead
Send the form data to the leads endpoint:
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" }
]
}'Step 3: Handle the response
On success, the API returns HTTP 201 with the created lead:
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"
}Node.js SDK example
Use the official SDK to integrate with an Express.js form handler:
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 });
});Next: Learn how to setup webhooks to get notified when leads are created.