> ## Documentation Index
> Fetch the complete documentation index at: https://leadtrackr.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Server-Side Lead

> Create a lead from your backend with API key authentication.

This endpoint is designed for **server-side** integrations. It requires an API key sent via the `X-API-Key` header.

If a lead with the same `uniqueEventId` already exists, it will be updated instead of duplicated.

## Request body

<ParamField body="projectId" type="string" required>
  The public ID of the project to create the lead in. You can find this in the [LeadTrackr Dashboard](https://app.leadtrackr.io) under **Settings**.
</ParamField>

<ParamField body="userData" type="object" required>
  Contact information for the lead.

  <Expandable title="userData properties">
    <ParamField body="firstName" type="string" optional>First name</ParamField>
    <ParamField body="lastName" type="string" optional>Last name</ParamField>
    <ParamField body="email" type="string" optional>Email address</ParamField>
    <ParamField body="phone" type="string" optional>Phone number (including country code, e.g. `+31612345678`)</ParamField>
    <ParamField body="companyName" type="string" optional>Company name</ParamField>
  </Expandable>
</ParamField>

<ParamField body="attributionData" type="object">
  Attribution and tracking data. At least one of `userData` or `attributionData` must contain data.

  <Expandable title="attributionData properties">
    <ParamField body="gclid" type="string" optional>Google Click ID</ParamField>
    <ParamField body="wbraid" type="string" optional>Google Web-to-App Broad ID</ParamField>
    <ParamField body="cid" type="string" optional>Google Analytics Client ID (e.g. `1234567890.1234567890`)</ParamField>
    <ParamField body="sid" type="string" optional>Google Analytics Session ID</ParamField>
    <ParamField body="fbp" type="string" optional>Facebook Browser ID (`_fbp` cookie value)</ParamField>
    <ParamField body="fbc" type="string" optional>Facebook Click ID (`_fbc` cookie value)</ParamField>
  </Expandable>
</ParamField>

<ParamField body="formData" type="object">
  Form submission data. You can include any additional custom fields — they are stored as-is.

  <Expandable title="formData properties">
    <ParamField body="formName" type="string" optional>Name of the form (e.g. `"Contact Form"`, `"Quote Request"`)</ParamField>
    <ParamField body="formMessage" type="string" optional>Message or description submitted with the form</ParamField>
    <ParamField body="uniqueEventId" type="string" optional>Unique identifier to deduplicate submissions. If a lead with the same `uniqueEventId` already exists in the project, the existing lead is updated instead of creating a duplicate.</ParamField>
  </Expandable>

  Any additional fields you include (e.g. `formCustomField1`, `campaign`, `source`) are passed through and stored as-is.
</ParamField>

<ParamField body="deviceData" type="object">
  Device and browser information. Used to improve attribution accuracy for GA4 and Meta integrations.

  <Expandable title="deviceData properties">
    <ParamField body="ipAddress" type="string" optional>IP address of the user</ParamField>
    <ParamField body="userAgent" type="string" optional>Browser user agent string</ParamField>
  </Expandable>
</ParamField>

<ParamField body="channelFlow" type="string">
  Channel flow tracking value (UTM journey). Also accepted as `lt_channelflow`.
</ParamField>

<ParamField body="uniqueIdentifier" type="string">
  A user-provided identifier to link this lead to your own system (e.g. your CRM lead ID or form submission ID). Max 255 characters. Also accepted as `unique_identifier`.
</ParamField>

## Response

<ResponseField name="message" type="string">
  A description of the result. Either `"Lead created successfully"` or `"Lead updated successfully"`.
</ResponseField>

<ResponseField name="leadId" type="number">
  The ID of the created or updated lead.
</ResponseField>

<ResponseField name="uniqueIdentifier" type="string | null">
  The unique identifier for the lead, or `null` if not provided.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://app.leadtrackr.io/api/leads/createServerSideLead \
    -H "Content-Type: application/json" \
    -H "X-API-Key: your-api-key-here" \
    -d '{
      "projectId": "your-project-id",
      "userData": {
        "firstName": "Jane",
        "lastName": "Smith",
        "email": "jane@example.com",
        "phone": "+31687654321",
        "companyName": "Acme Inc."
      },
      "attributionData": {
        "gclid": "xyz789",
        "cid": "9876543210.9876543210",
        "fbp": "fb.1.1612345678.9876543210"
      },
      "formData": {
        "formName": "Contact Form",
        "formMessage": "Interested in your services",
        "uniqueEventId": "evt_xyz789"
      },
      "deviceData": {
        "ipAddress": "203.0.113.50",
        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"
      },
      "uniqueIdentifier": "crm-lead-789"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://app.leadtrackr.io/api/leads/createServerSideLead", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": "your-api-key-here"
    },
    body: JSON.stringify({
      projectId: "your-project-id",
      userData: {
        firstName: "Jane",
        lastName: "Smith",
        email: "jane@example.com",
        phone: "+31687654321",
        companyName: "Acme Inc."
      },
      attributionData: {
        gclid: "xyz789",
        cid: "9876543210.9876543210"
      },
      formData: {
        formName: "Contact Form",
        uniqueEventId: "evt_xyz789"
      },
      uniqueIdentifier: "crm-lead-789"
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```php PHP theme={null}
  $ch = curl_init("https://app.leadtrackr.io/api/leads/createServerSideLead");

  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => [
          "Content-Type: application/json",
          "X-API-Key: your-api-key-here"
      ],
      CURLOPT_POSTFIELDS => json_encode([
          "projectId" => "your-project-id",
          "userData" => [
              "firstName" => "Jane",
              "lastName" => "Smith",
              "email" => "jane@example.com",
              "phone" => "+31687654321",
              "companyName" => "Acme Inc."
          ],
          "attributionData" => [
              "gclid" => "xyz789",
              "cid" => "9876543210.9876543210"
          ],
          "formData" => [
              "formName" => "Contact Form",
              "uniqueEventId" => "evt_xyz789"
          ],
          "uniqueIdentifier" => "crm-lead-789"
      ])
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  $data = json_decode($response, true);
  print_r($data);
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "message": "Lead created successfully",
    "leadId": 43,
    "uniqueIdentifier": "crm-lead-789"
  }
  ```
</ResponseExample>
