> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.trackleads.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.trackleads.io/_mcp/server.

# Lead anlegen oder aktualisieren

POST https://api.trackleads.io/api/v1/leads/upsert
Content-Type: application/json

Legt den Lead an, wenn es keinen Treffer gibt, und aktualisiert ihn sonst. Der Abgleich läuft über `email`, `phone` und `custom_id`. Mindestens eines der drei Felder muss gesetzt sein. Dieser Endpunkt ist der empfohlene Weg, Leads zu schreiben.

Reference: https://docs.trackleads.io/api/referenz/leads/upsert-lead

## Authentication

- `X-API-Key` header (required) — API-Key des Business. Alternativ als `Authorization: Bearer <key>`.

## Request

### Body (application/json)

This endpoint expects a LeadWrite.

- `email` (StringOrStringList, optional) — E-Mail-Adresse(n). Kennung für den Abgleich und gespeicherte Kontaktdaten.
- `phone` (StringOrStringList, optional) — Telefonnummer(n). Kennung für den Abgleich und gespeicherte Kontaktdaten.
- `custom_id` (string, optional) — Trackleads-Lead-ID aus einer früheren API-Antwort. Dient nur als Kennung.
- `name` (string, optional) — Vollständiger Name.
- `status` (string, optional) — Lead-Status, der gesetzt werden soll. Muss einem im Business konfigurierten Status entsprechen (API-Name, ersatzweise Anzeigename). Unbekannte Werte führen zu 422.
- `employee` (string, optional) — Person, die beim Statuswechsel vermerkt wird.
- `tags` (list of string, optional) — Tag-Namen, die hinzugefügt werden. Unbekannte Tags werden angelegt.
- `rm_tags` (list of string, optional) — Tag-Namen, die vom Lead entfernt werden.
- `rm_email` (StringOrStringList, optional) — E-Mail-Adressen, die vom Lead entfernt werden.
- `rm_phone` (StringOrStringList, optional) — Telefonnummern, die vom Lead entfernt werden.
- `utm_parameters` (map from string to any, optional) — Tracking-Parameter der Sitzung, die zu dieser Eintragung oder diesem Kauf geführt hat, zum Beispiel `utm_source`, `utm_campaign`, `fbclid`, `gclid` und vor allem `tlio_adid`. Werte sind einfache Werte oder Listen einfacher Werte. Ohne diese Parameter zählt der Lead als organisch.
- `funnel_url` (string, optional) — URL der Seite, auf der die Person konvertiert ist.
- `calendly_event` (string, optional) — URL eines Calendly-Events, das mit dem Lead verknüpft wird.

## Response

### 200

Der Lead existierte bereits und wurde aktualisiert.

- `ok` (boolean, optional)
- `id` (string, optional) — Trackleads-Lead-ID. Als `custom_id` in späteren Aufrufen nutzbar.
- `created` (boolean, optional) — `true`, wenn der Lead neu angelegt wurde.

### 201

Der Lead wurde neu angelegt.

- `ok` (boolean, optional)
- `id` (string, optional) — Trackleads-Lead-ID. Als `custom_id` in späteren Aufrufen nutzbar.
- `created` (boolean, optional) — `true`, wenn der Lead neu angelegt wurde.

## Errors

### 401 Unauthorized Error

API-Key fehlt oder ist ungültig.

- `ok` (boolean, optional)
- `error` (enum, optional)
  - Allowed values: `API_KEY_MISSING`, `API_KEY_INVALID`

### 422 Unprocessable Entity Error

Validierung fehlgeschlagen, zum Beispiel "Lead not found", eine doppelte `transaction_id` oder ein unbekannter Status.

- `message` (string, optional)
- `errors` (map from string to list of string, optional)

### 429 Too Many Requests Error

Rate-Limit überschritten. Warte die Sekunden aus dem Header `Retry-After` ab.

- `any`

## Types

### StringOrStringList

- string
- list of string

## Examples

### Leads_upsertLead_example

**Request**

```json
{
  "email": {
    "0": "jane@example.com"
  },
  "name": "Jane Doe",
  "tags": [
    "Webinar"
  ],
  "utm_parameters": {
    "tlio_adid": "120211478283920123",
    "utm_campaign": "launch",
    "utm_source": "facebook"
  },
  "funnel_url": "https://shop.example.com/checkout"
}
```

**Response**

```json
{
  "ok": true,
  "id": "K7Q2M9XA",
  "created": false
}
```

**SDK Code**

```python Leads_upsertLead_example
import requests

url = "https://api.trackleads.io/api/v1/leads/upsert"

payload = {
    "email": { "0": "jane@example.com" },
    "name": "Jane Doe",
    "tags": ["Webinar"],
    "utm_parameters": {
        "tlio_adid": "120211478283920123",
        "utm_campaign": "launch",
        "utm_source": "facebook"
    },
    "funnel_url": "https://shop.example.com/checkout"
}
headers = {
    "X-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Leads_upsertLead_example
const url = 'https://api.trackleads.io/api/v1/leads/upsert';
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"email":{"0":"jane@example.com"},"name":"Jane Doe","tags":["Webinar"],"utm_parameters":{"tlio_adid":"120211478283920123","utm_campaign":"launch","utm_source":"facebook"},"funnel_url":"https://shop.example.com/checkout"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Leads_upsertLead_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.trackleads.io/api/v1/leads/upsert"

	payload := strings.NewReader("{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-API-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Leads_upsertLead_example
require 'uri'
require 'net/http'

url = URI("https://api.trackleads.io/api/v1/leads/upsert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}"

response = http.request(request)
puts response.read_body
```

```java Leads_upsertLead_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.trackleads.io/api/v1/leads/upsert")
  .header("X-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}")
  .asString();
```

```php Leads_upsertLead_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.trackleads.io/api/v1/leads/upsert', [
  'body' => '{
  "email": {
    "0": "jane@example.com"
  },
  "name": "Jane Doe",
  "tags": [
    "Webinar"
  ],
  "utm_parameters": {
    "tlio_adid": "120211478283920123",
    "utm_campaign": "launch",
    "utm_source": "facebook"
  },
  "funnel_url": "https://shop.example.com/checkout"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Leads_upsertLead_example
using RestSharp;

var client = new RestClient("https://api.trackleads.io/api/v1/leads/upsert");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Leads_upsertLead_example
import Foundation

let headers = [
  "X-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "email": ["0": "jane@example.com"],
  "name": "Jane Doe",
  "tags": ["Webinar"],
  "utm_parameters": [
    "tlio_adid": "120211478283920123",
    "utm_campaign": "launch",
    "utm_source": "facebook"
  ],
  "funnel_url": "https://shop.example.com/checkout"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.trackleads.io/api/v1/leads/upsert")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Leads_upsertLead_example

**Request**

```json
{
  "email": {
    "0": "jane@example.com"
  },
  "name": "Jane Doe",
  "tags": [
    "Webinar"
  ],
  "utm_parameters": {
    "tlio_adid": "120211478283920123",
    "utm_campaign": "launch",
    "utm_source": "facebook"
  },
  "funnel_url": "https://shop.example.com/checkout"
}
```

**Response**

```json
{
  "ok": true,
  "id": "K7Q2M9XA",
  "created": true
}
```

**SDK Code**

```python Leads_upsertLead_example
import requests

url = "https://api.trackleads.io/api/v1/leads/upsert"

payload = {
    "email": { "0": "jane@example.com" },
    "name": "Jane Doe",
    "tags": ["Webinar"],
    "utm_parameters": {
        "tlio_adid": "120211478283920123",
        "utm_campaign": "launch",
        "utm_source": "facebook"
    },
    "funnel_url": "https://shop.example.com/checkout"
}
headers = {
    "X-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Leads_upsertLead_example
const url = 'https://api.trackleads.io/api/v1/leads/upsert';
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"email":{"0":"jane@example.com"},"name":"Jane Doe","tags":["Webinar"],"utm_parameters":{"tlio_adid":"120211478283920123","utm_campaign":"launch","utm_source":"facebook"},"funnel_url":"https://shop.example.com/checkout"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Leads_upsertLead_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.trackleads.io/api/v1/leads/upsert"

	payload := strings.NewReader("{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-API-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Leads_upsertLead_example
require 'uri'
require 'net/http'

url = URI("https://api.trackleads.io/api/v1/leads/upsert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}"

response = http.request(request)
puts response.read_body
```

```java Leads_upsertLead_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.trackleads.io/api/v1/leads/upsert")
  .header("X-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}")
  .asString();
```

```php Leads_upsertLead_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.trackleads.io/api/v1/leads/upsert', [
  'body' => '{
  "email": {
    "0": "jane@example.com"
  },
  "name": "Jane Doe",
  "tags": [
    "Webinar"
  ],
  "utm_parameters": {
    "tlio_adid": "120211478283920123",
    "utm_campaign": "launch",
    "utm_source": "facebook"
  },
  "funnel_url": "https://shop.example.com/checkout"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Leads_upsertLead_example
using RestSharp;

var client = new RestClient("https://api.trackleads.io/api/v1/leads/upsert");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"email\": {\n    \"0\": \"jane@example.com\"\n  },\n  \"name\": \"Jane Doe\",\n  \"tags\": [\n    \"Webinar\"\n  ],\n  \"utm_parameters\": {\n    \"tlio_adid\": \"120211478283920123\",\n    \"utm_campaign\": \"launch\",\n    \"utm_source\": \"facebook\"\n  },\n  \"funnel_url\": \"https://shop.example.com/checkout\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Leads_upsertLead_example
import Foundation

let headers = [
  "X-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "email": ["0": "jane@example.com"],
  "name": "Jane Doe",
  "tags": ["Webinar"],
  "utm_parameters": [
    "tlio_adid": "120211478283920123",
    "utm_campaign": "launch",
    "utm_source": "facebook"
  ],
  "funnel_url": "https://shop.example.com/checkout"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.trackleads.io/api/v1/leads/upsert")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```