Capture leads from a form
Turn each submission of a form on your website into a lead with its first step, safe to send twice.
On this page
Your server receives the submission and makes three calls: it finds the company, creates the lead and schedules the first step. The reference of the submission is the externalId of the lead, so a submission that arrives twice does not make two leads. Read Your own ids first if the idea is new.
Find the company
Look the company up by the CIF the visitor typed. If the list is empty, create the company as in the Quickstart and look it up again.
curl
curl "$RDC_BASE_URL/crm/v1/companies?cif=RO39172851" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/crm/v1/companies?cif=RO39172851`, {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
},
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'GET',
f'{os.environ["RDC_BASE_URL"]}/crm/v1/companies?cif=RO39172851',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/crm/v1/companies?cif=RO39172851');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
],
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/crm/v1/companies?cif=RO39172851");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"items": [
{
"id": "ffc05e95-9bb4-41f8-8389-0047121e711a",
"name": "Market Trei Brazi SRL",
"cif": "RO39172851",
"owner": "ana-rusu",
"status": "prospect",
"industry": "Grocery store",
"employees": 31,
"town": "Bacău",
"county": "Bacău",
"source": "form",
"summary": {
"text": "Grocery store in Bacău with a new shop opening. Left on price in October; two requests came through the website form since.",
"by": "ana-rusu",
"at": "2026-11-23"
},
"externalId": null,
"customFields": {},
"revision": 1
}
],
"nextCursor": null
} Create the lead
Send the lead with the id of the company and the reference of the submission, form-2026-11-23-0041, as externalId. Derive the operationId from the same reference, so that a repeated submission repeats the same request. Import from a file shows how.
curl
curl -X POST "$RDC_BASE_URL/crm/v1/deals" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "f35bd372-a5bd-47b7-8b15-bb7de414d172",
"companyId": "ffc05e95-9bb4-41f8-8389-0047121e711a",
"name": "Frozen goods, request from the form",
"owner": "ana-rusu",
"value": "45000.00",
"expectedClose": "2026-12-15",
"externalId": "form-2026-11-23-0041"
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/crm/v1/deals`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "f35bd372-a5bd-47b7-8b15-bb7de414d172",
"companyId": "ffc05e95-9bb4-41f8-8389-0047121e711a",
"name": "Frozen goods, request from the form",
"owner": "ana-rusu",
"value": "45000.00",
"expectedClose": "2026-12-15",
"externalId": "form-2026-11-23-0041"
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/crm/v1/deals',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': 'f35bd372-a5bd-47b7-8b15-bb7de414d172',
'companyId': 'ffc05e95-9bb4-41f8-8389-0047121e711a',
'name': 'Frozen goods, request from the form',
'owner': 'ana-rusu',
'value': '45000.00',
'expectedClose': '2026-12-15',
'externalId': 'form-2026-11-23-0041',
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "f35bd372-a5bd-47b7-8b15-bb7de414d172",
"companyId": "ffc05e95-9bb4-41f8-8389-0047121e711a",
"name": "Frozen goods, request from the form",
"owner": "ana-rusu",
"value": "45000.00",
"expectedClose": "2026-12-15",
"externalId": "form-2026-11-23-0041"
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/crm/v1/deals');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/crm/v1/deals");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "f35bd372-a5bd-47b7-8b15-bb7de414d172",
"companyId": "ffc05e95-9bb4-41f8-8389-0047121e711a",
"name": "Frozen goods, request from the form",
"owner": "ana-rusu",
"value": "45000.00",
"expectedClose": "2026-12-15",
"externalId": "form-2026-11-23-0041"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "f35bd372-a5bd-47b7-8b15-bb7de414d172",
"status": "accepted",
"aggregateRevision": 1
} Schedule the first step
A lead nobody has a task on goes quiet. Schedule the first step on the lead. The revision of a new lead is 1, and scheduling the step makes it 2.
curl
curl -X POST "$RDC_BASE_URL/crm/v1/deals/d4a1f7c8-3e90-4b56-a2d1-8c7e0b9f6a44/tasks" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "763efd8a-0650-4367-994c-3b794bbba1fa",
"expectedRevision": 1,
"kind": "task",
"text": "Qualify the request.",
"due": "2026-11-24"
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/crm/v1/deals/d4a1f7c8-3e90-4b56-a2d1-8c7e0b9f6a44/tasks`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "763efd8a-0650-4367-994c-3b794bbba1fa",
"expectedRevision": 1,
"kind": "task",
"text": "Qualify the request.",
"due": "2026-11-24"
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/crm/v1/deals/d4a1f7c8-3e90-4b56-a2d1-8c7e0b9f6a44/tasks',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': '763efd8a-0650-4367-994c-3b794bbba1fa',
'expectedRevision': 1,
'kind': 'task',
'text': 'Qualify the request.',
'due': '2026-11-24',
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "763efd8a-0650-4367-994c-3b794bbba1fa",
"expectedRevision": 1,
"kind": "task",
"text": "Qualify the request.",
"due": "2026-11-24"
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/crm/v1/deals/d4a1f7c8-3e90-4b56-a2d1-8c7e0b9f6a44/tasks');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/crm/v1/deals/d4a1f7c8-3e90-4b56-a2d1-8c7e0b9f6a44/tasks");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "763efd8a-0650-4367-994c-3b794bbba1fa",
"expectedRevision": 1,
"kind": "task",
"text": "Qualify the request.",
"due": "2026-11-24"
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "763efd8a-0650-4367-994c-3b794bbba1fa",
"status": "accepted",
"aggregateRevision": 2
} When a submission repeats
| Situation | Answer |
|---|---|
The same submission, the same operationId: the form was sent twice, or your server retried. | 202 |
The same externalId with a new operationId: another request claims the reference. | 409 |
| A second submission from the same company, with its own reference: a second lead. | 202 |
The second lead of a company is a likely duplicate of the first. Find and merge duplicates takes it from there.