API Error: Invalid type — expected integer, received string
A request field has the wrong data type — a string where the API expects a number, a number where it expects a boolean, an object instead of an array.
Meaning
The API validates each field against a schema before processing. Values that look right to a human (“42”, “true”) are strings in JSON unless written without quotes, and form/query-string values are always strings until the server converts them.
Validators phrase it differently: Zod says “Expected number, received string”, JSON Schema/Ajv says “must be integer”, Pydantic says “Input should be a valid integer”, Stripe says “Invalid integer”.
Common causes
- Numeric or boolean values sent in quotes ("42", "true")
- Values read from a form, URL or CSV are strings and weren’t converted
- A single value sent where an array is expected (or the reverse)
- null sent for a non-nullable field
- Client model and API schema drifted apart
⚡ Quick fix
- Convert values to the documented type before sending (Number(), parseInt, bool)
- Send JSON numbers/booleans without quotes
- Check the schema for arrays vs single values and nullability
Detailed fix by platform
Node.js
const body = { quantity: Number(form.quantity), active: form.active === 'on', tags: [].concat(form.tags ?? []) };
Python
payload = {"quantity": int(qty), "active": active == "true"} # JSON numbers/booleans, not strings
How to diagnose
- Field — Which field and which expected type does the error name?
- Serialized body — Is the value quoted in the JSON actually sent?
- Schema — Array vs single value, nullable or not?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Report a correction or suggest an improvement
Last updated 7 Oct 2026