invalid_type 🔌 API

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.

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