Zielgruppen-Lebenszyklus
Dieser Leitfaden führt Sie durch den vollständigen Lebenszyklus einer Zielgruppe: Bootstrapping aus einer URL, Erstellen, Aktualisieren und Löschen.
Was Sie erstellen werden
- Ein demografisches Profil aus einer URL erzeugen
- Eine Zielgruppe aus diesem Profil erstellen
- Sie abrufen, aktualisieren und löschen
Voraussetzungen
- Ein neuroflash-Konto mit API-Zugang
- Ihre
client_idundclient_secret(siehe Authentifizierung)
Schritt 1: Authentifizieren
- cURL
- Python
- Node.js
- Go
curl -X POST https://id.neuroflash.com/oauth/v2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "scope=openid"
import requests
BASE_URL = "https://app.neuroflash.com/api"
token = requests.post(
"https://id.neuroflash.com/oauth/v2/token",
data={"grant_type": "client_credentials", "client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET", "scope": "openid"},
).json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
const BASE_URL = "https://app.neuroflash.com/api";
const { access_token } = await fetch("https://id.neuroflash.com/oauth/v2/token", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
scope: "openid",
}),
}).then((r) => r.json());
const headers = { Authorization: `Bearer ${access_token}` };
data := url.Values{
"grant_type": {"client_credentials"},
"client_id": {"YOUR_CLIENT_ID"},
"client_secret": {"YOUR_CLIENT_SECRET"},
"scope": {"openid"},
}
resp, _ := http.Post("https://id.neuroflash.com/oauth/v2/token",
"application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
defer resp.Body.Close()
Schritt 2: Arbeitsbereich abrufen
- cURL
- Python
- Node.js
- Go
curl "https://app.neuroflash.com/api/workspace-service/v1/workspaces" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
workspaces = requests.get(f"{BASE_URL}/workspace-service/v1/workspaces", headers=headers).json()
workspace_id = workspaces["_embedded"]["workspaces"][0]["id"]
const workspaces = await fetch(`${BASE_URL}/workspace-service/v1/workspaces`, { headers })
.then((r) => r.json());
const workspaceId = workspaces._embedded.workspaces[0].id;
req, _ := http.NewRequest("GET", baseURL+"/workspace-service/v1/workspaces", nil)
req.Header.Set("Authorization", "Bearer "+token)
Schritt 3: Aus URL erzeugen (schnellster Weg)
Dies gibt ein vorbereitetes demografisches Profil zurück, keine gespeicherte Zielgruppe. Übergeben Sie die Antwortfelder im nächsten Schritt direkt an den Create-Endpunkt.
- cURL
- Python
- Node.js
- Go
curl -X POST "https://app.neuroflash.com/api/audience-service/v1/workspaces/{workspace_id}/target-audiences-url-imports" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"audienceModelId": "538b1efc6f88ad88feebf7acd8c618facb54fe82",
"urls": ["https://your-brand.com"]
}'
profile = requests.post(
f"{BASE_URL}/audience-service/v1/workspaces/{workspace_id}/target-audiences-url-imports",
headers={**headers, "Content-Type": "application/json"},
json={
"audienceModelId": "538b1efc6f88ad88feebf7acd8c618facb54fe82",
"urls": ["https://your-brand.com"],
},
).json()
const profile = await fetch(
`${BASE_URL}/audience-service/v1/workspaces/${workspaceId}/target-audiences-url-imports`,
{
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({
audienceModelId: "538b1efc6f88ad88feebf7acd8c618facb54fe82",
urls: ["https://your-brand.com"],
}),
}
).then((r) => r.json());
body, _ := json.Marshal(map[string]any{
"audienceModelId": "538b1efc6f88ad88feebf7acd8c618facb54fe82",
"urls": []string{"https://your-brand.com"},
})
req, _ := http.NewRequest("POST",
baseURL+"/audience-service/v1/workspaces/"+workspaceID+"/target-audiences-url-imports",
bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
Schritt 4: Zielgruppe erstellen
Die vier Felder in genderDistribution (female, male, nonBinary, preferNotToSay) sind
alle erforderlich und ihre Werte müssen in Summe exakt 1.0 ergeben. Die API gibt einen 400-Fehler
zurück, wenn ein Feld fehlt oder die Summe nicht stimmt.
- cURL
- Python
- Node.js
- Go
curl -X POST "https://app.neuroflash.com/api/audience-service/v1/workspaces/{workspace_id}/target-audiences" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"country": "US",
"genderDistribution": {
"female": 0.5,
"male": 0.4,
"nonBinary": 0.07,
"preferNotToSay": 0.03
},
"interests": ["AI", "content marketing"],
"maxAge": 45,
"minAge": 25,
"name": "Marketing leaders",
"nativeLanguage": "en",
"needs": ["scale content production"],
"painPoints": ["manual workflows"],
"residence": "Berlin",
"shared": true
}'
created = requests.post(
f"{BASE_URL}/audience-service/v1/workspaces/{workspace_id}/target-audiences",
headers={**headers, "Content-Type": "application/json"},
json={
"country": "US",
"genderDistribution": {"female": 0.5, "male": 0.4, "nonBinary": 0.07, "preferNotToSay": 0.03},
"interests": ["AI", "content marketing"],
"maxAge": 45,
"minAge": 25,
"name": "Marketing leaders",
"nativeLanguage": "en",
"needs": ["scale content production"],
"painPoints": ["manual workflows"],
"residence": "Berlin",
"shared": True,
},
).json()
target_audience_id = created["id"]
const created = await fetch(
`${BASE_URL}/audience-service/v1/workspaces/${workspaceId}/target-audiences`,
{
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({
country: "US",
genderDistribution: { female: 0.5, male: 0.4, nonBinary: 0.07, preferNotToSay: 0.03 },
interests: ["AI", "content marketing"],
maxAge: 45,
minAge: 25,
name: "Marketing leaders",
nativeLanguage: "en",
needs: ["scale content production"],
painPoints: ["manual workflows"],
residence: "Berlin",
shared: true,
}),
}
).then((r) => r.json());
const targetAudienceId = created.id;
body, _ := json.Marshal(map[string]any{
"country": "US",
"genderDistribution": map[string]float64{
"female": 0.5, "male": 0.4, "nonBinary": 0.07, "preferNotToSay": 0.03,
},
"interests": []string{"AI", "content marketing"},
"maxAge": 45, "minAge": 25,
"name": "Marketing leaders",
"nativeLanguage": "en",
"needs": []string{"scale content production"},
"painPoints": []string{"manual workflows"},
"residence": "Berlin",
"shared": true,
})
req, _ := http.NewRequest("POST",
baseURL+"/audience-service/v1/workspaces/"+workspaceID+"/target-audiences",
bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
Schritt 5: Zielgruppe abrufen
- cURL
- Python
- Node.js
- Go
curl "https://app.neuroflash.com/api/audience-service/v1/workspaces/{workspace_id}/target-audiences/{target_audience_id}" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
audience = requests.get(
f"{BASE_URL}/audience-service/v1/workspaces/{workspace_id}/target-audiences/{target_audience_id}",
headers=headers,
).json()
const audience = await fetch(
`${BASE_URL}/audience-service/v1/workspaces/${workspaceId}/target-audiences/${targetAudienceId}`,
{ headers }
).then((r) => r.json());
req, _ := http.NewRequest("GET",
baseURL+"/audience-service/v1/workspaces/"+workspaceID+"/target-audiences/"+targetAudienceID, nil)
req.Header.Set("Authorization", "Bearer "+token)
Schritt 6: Zielgruppe aktualisieren
Der Update-Endpunkt verwendet PUT-Semantik — Sie müssen bei jedem Aufruf das vollständige demografische Profil übergeben, auch wenn Sie nur ein Feld ändern möchten. Rufen Sie die Zielgruppe zuerst ab und senden Sie dann alle bestehenden Werte mit Ihrer Änderung zurück.
- cURL
- Python
- Node.js
- Go
curl -X PUT "https://app.neuroflash.com/api/audience-service/v1/workspaces/{workspace_id}/target-audiences/{target_audience_id}" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "...": "full demographic profile here" }'
audience["name"] = "Senior marketing leaders"
requests.put(
f"{BASE_URL}/audience-service/v1/workspaces/{workspace_id}/target-audiences/{target_audience_id}",
headers={**headers, "Content-Type": "application/json"},
json=audience,
)
audience.name = "Senior marketing leaders";
await fetch(
`${BASE_URL}/audience-service/v1/workspaces/${workspaceId}/target-audiences/${targetAudienceId}`,
{
method: "PUT",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify(audience),
}
);
// Re-serialise the previously fetched audience with your modifications, then PUT it back.
req, _ := http.NewRequest("PUT",
baseURL+"/audience-service/v1/workspaces/"+workspaceID+"/target-audiences/"+targetAudienceID,
bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
Schritt 7: Zielgruppe löschen
Nur der Benutzer, der eine Zielgruppe erstellt hat, kann diese aktualisieren oder löschen.
Der Versuch, eine Ressource eines anderen Benutzers zu ändern, gibt 403 Forbidden zurück.
- cURL
- Python
- Node.js
- Go
curl -X DELETE "https://app.neuroflash.com/api/audience-service/v1/workspaces/{workspace_id}/target-audiences/{target_audience_id}" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
requests.delete(
f"{BASE_URL}/audience-service/v1/workspaces/{workspace_id}/target-audiences/{target_audience_id}",
headers=headers,
)
await fetch(
`${BASE_URL}/audience-service/v1/workspaces/${workspaceId}/target-audiences/${targetAudienceId}`,
{ method: "DELETE", headers }
);
req, _ := http.NewRequest("DELETE",
baseURL+"/audience-service/v1/workspaces/"+workspaceID+"/target-audiences/"+targetAudienceID, nil)
req.Header.Set("Authorization", "Bearer "+token)
Das genderDistribution-Objekt
Alle vier Schlüssel sind erforderlich und die Werte müssen in Summe exakt 1.0 ergeben:
| Schlüssel | Beschreibung |
|---|---|
female | Anteil, der sich als weiblich identifiziert |
male | Anteil, der sich als männlich identifiziert |
nonBinary | Anteil, der sich als nicht-binär identifiziert |
preferNotToSay | Anteil, der keine Angabe machen möchte |
Ein üblicher Startpunkt: female: 0.5, male: 0.4, nonBinary: 0.07, preferNotToSay: 0.03.