Errors
Validation Error
422 - Request parameters failed validation
Overview
The 422 Validation Error occurs when the request parameters do not meet the required validation rules. This error provides detailed information about which fields failed validation and why.
HTTP Status Code
422
Error Response
{
"type": "https://scan-documents.com/docs/errors/validation-error",
"title": "Validation Error",
"status": 422,
"errors": {
"input": [
"input does not contain a valid input id."
],
"format": [
"format must be one of: pdf, png, jpg"
]
}
}Response Structure
The errors object contains field names as keys, with arrays of error messages as values. Each field that failed validation will be listed with one or more specific error messages.
Common Causes
- Missing required fields in the request body
- Invalid data types (e.g., string instead of number)
- Values that don't match expected formats or patterns
- Values outside acceptable ranges
- Invalid enum values
- Malformed IDs or references to other resources
How to Fix
- Review Error Messages: Examine the
errorsobject in the response to identify which fields failed validation:
{
"errors": {
"input": ["input does not contain a valid input id."],
"quality": ["quality must be between 1 and 100"]
}
}- Check Required Fields: Ensure all required fields are included in your request:
// Example: Creating a task with all required fields
const response = await fetch('https://api.scan-documents.com/v1/image-operations/convert', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
input: 'file_abc123def456', // Required
format: 'pdf' // Required
})
});- Validate Data Types: Ensure you're sending the correct data types:
// Incorrect - sending string instead of number
{ "quality": "80" }
// Correct - sending number
{ "quality": 80 }- Check API Documentation: Refer to the specific endpoint documentation to understand all validation requirements for each field.
Examples
Missing Required Field
Request:
{
"format": "pdf"
// Missing required "input" field
}Response:
{
"type": "https://scan-documents.com/docs/errors/validation-error",
"title": "Validation Error",
"status": 422,
"errors": {
"input": ["input is required."]
}
}Invalid Enum Value
Request:
{
"input": "file_abc123def456",
"format": "docx" // Not a valid format
}Response:
{
"type": "https://scan-documents.com/docs/errors/validation-error",
"title": "Validation Error",
"status": 422,
"errors": {
"format": ["format must be one of: pdf, png, jpg, jpeg, webp"]
}
}Multiple Validation Errors
Request:
{
"quality": 150, // Out of range
"format": "invalid" // Invalid enum
}Response:
{
"type": "https://scan-documents.com/docs/errors/validation-error",
"title": "Validation Error",
"status": 422,
"errors": {
"input": ["input is required."],
"quality": ["quality must be between 1 and 100"],
"format": ["format must be one of: pdf, png, jpg, jpeg, webp"]
}
}Related Errors
- Unsupported File Type - File format not supported
- Not Found - Referenced resource doesn't exist