Invalid Data Type
When the data sent does not meet the requirements expected by the API, it is possible to receive an error response with specific details about the fields that caused the problem. In such cases, the API will typically return a status code of 422 Unprocessable Entity, indicating that the request was well-formed but contained semantic errors that prevented it from being processed.
The response body typically indicates these issues using the TYPE_MISMATCH error type.
Handling Errors of the Track Endpoint
The example below explains how to handle invalid data type errors when leveraging the track endpoint of the Reserhub Data Lake API
Request Body
{ "event_name": "purchase_complete", "event_data": { "passenger_count": 2, "payment_type": "credit_card", "trips_count": 1, "tickets": 2, "total": 31.00, "product": false, "email": "john.doe@example.com", "phone": "+12154567890", "trips": [{ "departure_arrival": "2025-04-25T10:30:00-05:00", "departure_destination": "Boston", "departure_destination_terminal": "South Station", "departure_line": "Coastal Express", "departure_origin": "New York", "departure_origin_terminal": "Port Authority", "departure_price": 15.50, "departure_route": "NY-BOS", "departure_stop_cities": "", "departure_stops": [], "departure_time": "2025-04-25T15:30:00-05:00", "departure_transporter": "East Coast Bus Company", "bus_categories": false, "departure_transport_type": "bus" }] }}Response
{ "errors": [ { "error_type": "TYPE_MISMATCH", "expected": "string", "field": "bus_categories", "message": "Invalid type for field bus_categories. Expected string.", "received": "boolean", "suggestion": "Ensure that the bus_categories field is a string." }, { "error_type": "TYPE_MISMATCH", "expected": "integer", "field": "departure_stops", "message": "Invalid type for field departure_stops. Expected integer.", "received": "array", "suggestion": "Ensure that the departure_stops field is an integer." }, { "error_type": "TYPE_MISMATCH", "expected": "string", "field": "product", "message": "Invalid type for field product. Expected string.", "received": "boolean", "suggestion": "Ensure that the product field is a string." } ], "message": "Validation failed. See details for more information.", "status": "error"}Solution
The solution involves correcting the data types: changing bus_categories from boolean to string (e.g., "general"), departure_stops from array to integer (e.g., 0), and product from boolean to string (e.g., "ios").
{ "event_name": "purchase_complete", "event_data": { "passenger_count": 2, "payment_type": "credit_card", "trips_count": 1, "tickets": 2, "total": 31.00, "product": "ios", "email": "john.doe@example.com", "phone": "+12154567890", "trips": [{ "departure_arrival": "2025-04-25T10:30:00-05:00", "departure_destination": "Boston", "departure_destination_terminal": "South Station", "departure_line": "Coastal Express", "departure_origin": "New York", "departure_origin_terminal": "Port Authority", "departure_price": 15.50, "departure_route": "NY-BOS", "departure_stop_cities": "", "departure_stops": 0, "departure_time": "2025-04-25T15:30:00-05:00", "departure_transporter": "East Coast Bus Company", "bus_categories": "general", "departure_transport_type": "bus" }] }}Handling Errors of the Identify Endpoint
The following example illustrates how to handle invalid data type errors when using the identify endpoint of the Reserhub Data Lake API.
Request Body
{ "profile_params": { "distinct_id": "1234567890", "first_name": false, "last_name": false, "name": "John Doe", "email": "john.doe@example.com", "phone": "+12154567890", "birthdate": "1990-01-01", "country_code": "US", "city": "New York" }, "product": "web-mobile"}Response
{ "errors": [ { "error_type": "TYPE_MISMATCH", "expected": "string", "field": "first_name", "message": "Invalid type for field first_name. Expected string.", "received": "boolean", "suggestion": "Ensure that the first_name field is a string." }, { "error_type": "TYPE_MISMATCH", "expected": "string", "field": "last_name", "message": "Invalid type for field last_name. Expected string.", "received": "boolean", "suggestion": "Ensure that the last_name field is a string." } ], "message": "Validation failed. See details for more information.", "status": "error"}Solution
The solution involves changing the boolean values for first_name and last_name to the correct string format.
{ "profile_params": { "distinct_id": "1234567890", "first_name": "John", "last_name": "Doe", "name": "John Doe", "email": "john.doe@example.com", "phone": "+12154567890", "birthdate": "1990-01-01", "country_code": "US", "city": "New York" }, "product": "web-mobile"}