Fehler
Die neuroflash API verwendet standardisierte HTTP-Statuscodes und gibt strukturierte Fehlerantworten zurück.
HTTP-Statuscodes
| Statuscode | Bedeutung |
|---|---|
200 | OK — Anfrage erfolgreich |
201 | Created — Ressource wurde erstellt |
204 | No Content — Anfrage erfolgreich, ohne Antwortinhalt |
400 | Bad Request — Ungültige Anfrageparameter oder -inhalt |
401 | Unauthorized — Fehlender oder ungültiger Access Token |
403 | Forbidden — Unzureichende Berechtigungen oder Limit erreicht |
404 | Not Found — Ressource existiert nicht |
422 | Unprocessable Entity — Validierungsfehler |
429 | Too Many Requests — Rate Limit oder Kontingent überschritten |
500 | Internal Server Error — Auf unserer Seite ist ein Fehler aufgetreten |
Format der Fehlerantwort
Fehlerantworten enthalten ein error-Feld mit einer lesbaren Nachricht und, sofern zutreffend, ein code-Feld für die programmatische Fehlerbehandlung:
{
"error": "Target audience limit reached for this workspace",
"code": "TARGET_AUDIENCE_LIMIT_REACHED"
}
Validierungsfehler
Einige Endpoints geben detaillierte Validierungsfehler mit Informationen auf Feldebene zurück:
{
"errors": [
{
"field": "name",
"message": "must be between 3 and 100 characters",
"type": "validation"
}
]
}
Häufige Fehlercodes
| Code | Beschreibung |
|---|---|
TARGET_AUDIENCE_LIMIT_REACHED | Der Workspace hat sein Limit für die Erstellung von Zielgruppen erreicht |
MAX_BRAND_VOICES_REACHED | Der Workspace hat sein Limit für die Erstellung von Brand Voices erreicht |
Fehlerbehandlung
- cURL
- Python
- Node.js
- Go
# Example: handle error responses
response=$(curl -s -w "\n%{http_code}" -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 '{"name": "My Audience"}')
http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 201 ]; then
echo "Created: $body"
else
echo "Error $http_code: $body"
fi
import requests
response = requests.post(
"https://app.neuroflash.com/api/audience-service/v1/workspaces/{workspace_id}/target-audiences",
headers={"Authorization": f"Bearer {token}"},
json=payload,
)
if response.status_code == 201:
audience = response.json()
print(f"Created audience: {audience['id']}")
elif response.status_code == 403:
error = response.json()
if error.get("code") == "TARGET_AUDIENCE_LIMIT_REACHED":
print("Upgrade your plan to create more audiences")
else:
print(f"Forbidden: {error['error']}")
else:
print(f"Error {response.status_code}: {response.text}")
const response = await fetch(
`https://app.neuroflash.com/api/audience-service/v1/workspaces/${workspaceId}/target-audiences`,
{
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
}
);
if (response.ok) {
const audience = await response.json();
console.log(`Created audience: ${audience.id}`);
} else {
const error = await response.json();
console.error(`Error ${response.status}: ${error.error}`);
}
req, _ := http.NewRequest("POST",
"https://app.neuroflash.com/api/audience-service/v1/workspaces/"+workspaceID+"/target-audiences",
bytes.NewReader(payload))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
if resp.StatusCode == 201 {
var audience struct {
ID string `json:"id"`
}
json.NewDecoder(resp.Body).Decode(&audience)
fmt.Printf("Created audience: %s\n", audience.ID)
} else {
var apiErr struct {
Error string `json:"error"`
Code string `json:"code"`
}
json.NewDecoder(resp.Body).Decode(&apiErr)
fmt.Printf("Error %d: %s\n", resp.StatusCode, apiErr.Error)
}