Validation failed
VALIDATION_FAILED comes with HTTP 400. A field of your request, or your query, is not valid.
What it means
The API checked your request and found at least one problem. Nothing was searched. The errors array lists every problem it found, so you can fix them all at once.
Each entry has:
field: the request field, for exampleeventTypesorlimit. A problem in the query language uses the field namebadQuery.issue: a readable text. The wording can change, so show it to people but do not parse it.allowedValues: only for fields with a fixed list of values (include,orderBy,order,roles,eventTypes,eventDirections,minImportance,sourceTypes,excludeSourceTypes).
The detail says how many fields failed: 1 request field is not valid. or 3 request fields are not valid.
Example response
A wrong value in a field with a fixed list:
Request
curl -X POST 'https://api.finlight.me/v3/articles/search' \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: YOUR_API_KEY' \
-H 'X-Request-Id: req-123' \
-d '{ "eventTypes": ["earnigns"] }'
Response (400)
{
"type": "https://docs.finlight.me/errors/validation-failed",
"title": "Validation failed",
"status": 400,
"detail": "1 request field is not valid.",
"code": "VALIDATION_FAILED",
"requestId": "req-123",
"errors": [
{
"field": "eventTypes",
"issue": "each value in eventTypes must be one of the following values: earnings, guidance, mna, ipo_listing, capital_action, rating_action, management_change, legal, regulatory, bankruptcy_distress, product_partnership, investment_expansion, operational_incident, labor_restructuring, macro, geopolitics",
"allowedValues": [
"earnings", "guidance", "mna", "ipo_listing", "capital_action",
"rating_action", "management_change", "legal", "regulatory",
"bankruptcy_distress", "product_partnership", "investment_expansion",
"operational_incident", "labor_restructuring", "macro", "geopolitics"
]
}
]
}
Several problems at once, for the body {"limit": 500, "order": "DESC"}:
Response (400)
{
"type": "https://docs.finlight.me/errors/validation-failed",
"title": "Validation failed",
"status": 400,
"detail": "2 request fields are not valid.",
"code": "VALIDATION_FAILED",
"requestId": "req-123",
"errors": [
{ "field": "order", "issue": "order must be one of the following values: asc, desc", "allowedValues": ["asc", "desc"] },
{ "field": "limit", "issue": "limit must not be greater than 100" }
]
}
Common causes
| Request | field | issue |
|---|---|---|
A value that is not in the list, for example "eventTypes": ["earnigns"] | eventTypes | each value in eventTypes must be one of the following values: earnings, ... |
"sourceTypes": ["wire"] | sourceTypes | each value in sourceTypes must be one of the following values: newswire, press_release, financial_media, general_media, aggregator, blog, government |
"countries": ["USA"] | countries | each value in countries must be a valid ISO31661 Alpha2 code |
"order": "DESC" (values are lower case) | order | order must be one of the following values: asc, desc |
"limit": 0 | limit | limit must not be less than 1 |
"limit": 500 | limit | limit must not be greater than 100 |
"languages": [] | languages | languages should not be empty |
sources and optInSources together | optInSources | Can't have optInSources and sources defined simultaneously |
An unknown field in the query, for example colour:blue | badQuery | Unknown field "colour". Allowed fields: category, companyCount, ... To search for the literal text, quote it: "colour:blue". |
GET /v3/companies without q and without ids | q and ids | Either q or ids has to be given. |
GET /v3/companies?q=NVDA&ids=1 | ids | q and ids cannot be combined. Use one of the two. |
GET /v3/companies?ids=1,abc | ids | each value in ids must not be less than 1, each value in ids must be an integer number |
GET /v3/companies/abc | companyId | companyId has to be a whole number. |
Other query language problems also use the field badQuery and explain the problem in issue. A few query checks name the rule instead of a request field:
| Query | field | issue |
|---|---|---|
Only negative terms, for example -tesla | positiveTermRequired | Query must include at least one non-negative keyword or phrase |
| No usable term at all | missingTerm | Query must include at least one valid keyword or phrase |
| Too many terms or too deeply nested | complexity | for example Query too large (max 2000 terms) |
| More than 20,000 characters | maxLength | Query must be at most 20000 characters long |
See Query syntax.
Two things do not cause this error:
- Unknown request fields are dropped without an error. A misspelled field name, such as
eventTypeinstead ofeventTypes, means the filter is simply not applied. The client libraries reject unknown fields before they send anything. - A date range outside your plan is cut to your plan's window without an error. See Plans & entitlements.
A request body that is not valid JSON also gets a 400, but in a simpler form without code. See Responses that are not problem+json.
How to fix
- Read
errors[]. Each entry names the field and the problem. - For a field with
allowedValues, pick one of those values. Values are case-sensitive. - For
badQuery, check the field names in Fields. Put free text that contains a:in double quotes. - Send the corrected request.
Retry
Do not retry. The same request fails the same way. The client libraries never retry a 400.
A request that fails this check still costs 1 credit, on the article routes and on the company lookup alike. See Rate limits & credits.
In the SDKs
| Language | Error |
|---|---|
| TypeScript, Python, Ruby | ValidationFailedError |
| .NET, Java, PHP | ValidationFailedException |
| Go | *finlight.APIError with APIKind == finlight.APIKindValidationFailed |
| Rust | Error::Api with api_kind() == ApiErrorKind::ValidationFailed |
The entries of errors[] are available as errors (field, issue, allowed values).
Some mistakes never reach the API. The libraries check limit (1 to 100), empty languages, unknown arguments and the q/ids rule of the company lookup themselves and raise a local validation error (FinlightValidationError in TypeScript and Python; an unknown argument in Python is a TypeError). Those cost nothing.
Catch a validation error
import { ValidationFailedError } from 'finlight-client'
try {
await client.articles.search({ eventTypes: ['earnigns'] })
} catch (err) {
if (err instanceof ValidationFailedError) {
for (const e of err.errors) {
console.log(e.field, e.issue, e.allowedValues)
}
} else {
throw err
}
}
On WebSocket
A subscribe message that is not valid gets a connection.error frame with the code VALIDATION_FAILED. Then the server closes the connection. Do not reconnect with the same message. The client libraries end the stream with a validation error.
On the WebSocket the problems are in details[], each with field and constraints:
connection.error
{
"event": "connection.error",
"payloadVersion": 3,
"data": {
"code": "VALIDATION_FAILED",
"message": "Invalid subscription message",
"details": [
{
"field": "sourceTypes",
"constraints": {
"isIn": "each value in sourceTypes must be one of the following values: newswire, press_release, financial_media, general_media, aggregator, blog, government"
},
"allowedValues": ["newswire", "press_release", "financial_media", "general_media", "aggregator", "blog", "government"]
}
]
}
}
Common causes on the WebSocket:
- A v2 key in a v3 subscribe:
includeEntitiesorextendedtogether with"payloadVersion": 3. Useincludeinstead. The constraint text isuse include with payloadVersion 3. - An unknown value in
sourceTypes,excludeSourceTypesor (enriched only)include. - Any
includeon the raw stream. Raw delivers only the basic article fields.
See Subscribe and Raw stream.