invalid_type API Origin: Application & API Last updated 14 Oct 2026

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.

Exact message you may see Expected number, received stringExpected string, received numbermust be integermust be numbermust be string
Seen on: REST API

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

  1. Convert values to the documented type before sending (Number(), parseInt, bool)
  2. Send JSON numbers/booleans without quotes
  3. Check the schema for arrays vs single values and nullability

Detailed fix by platform

Node.js

  1. const body = { quantity: Number(form.quantity), active: form.active === 'on', tags: [].concat(form.tags ?? []) };

Python

  1. payload = {"quantity": int(qty), "active": active == "true"} # JSON numbers/booleans, not strings

How to diagnose

  1. Field — Which field and which expected type does the error name?
  2. Serialized body — Is the value quoted in the JSON actually sent?
  3. Schema — Array vs single value, nullable or not?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

1048 — MySQL ERROR 1048 (23000): Column 'x' cannot be null (MySQL)10481264 — MySQL ERROR 1264 (22003): Out of range value for column 'x' at row 1 (MySQL)12641292 — MySQL ERROR 1292 (22007): Incorrect datetime value: 'x' for column 'y' (MySQL)12921366 — MySQL ERROR 1366 (HY000): Incorrect integer value: '' for column 'x' at row 1 (MySQL)13661406 — MySQL ERROR 1406: Data too long for column (MySQL)14061690 — MySQL ERROR 1690 (22003): BIGINT UNSIGNED value is out of range (MySQL)169022001 — ERROR: value too long for type character varying(255) (PostgreSQL)2200122003 — ERROR: numeric field overflow — A field with precision 5, scale 2 must round to an absolute value less than 10^3 (PostgreSQL)22003invalid_t…

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.