1. Support arrow-right
  2. 400 Bad Request - Invalid/malformed JSON in request

400 Bad Request - Invalid/malformed JSON in request

Think of a 400 Bad Request error as the system saying, "I can hear you, but I don't quite understand what you’re asking for." The good news is that your connection and authentication are working! 

A 400 error can occur for various reasons. Luckily, ItemPath typically returns a specific error message alongside the 400 status code. If the error message indicates "Invalid/malformed JSON in request", this means there is something a little "off" with the JSON package you’re sending. Usually, it’s just a tiny typo or a missing detail that’s preventing ItemPath from processing your request.

 

Common Causes of Bad JSON

When sending Orders or Materials, the most common culprits for a 400 error include:

  1. Syntax Errors:
    • Missing or extra commas: Forgetting a comma between key-value pairs or leaving a "trailing comma" at the end of a list.
    • Unmatched brackets: Every opening brace { or bracket [ needs its partner to close it.
    • “Smart” Quotes: If you copy-pasted from a document, you might have “curly” quotes instead of the standard "straight" quotes (") the API requires.
  2. Missing Required Fields:
    • Orders: Every order requires a name (the unique order number) and an order_lines array.
    • Materials: Creating a material requires a name.
  3. Data Type Mismatches: Sending a string where an integer is expected (e.g., sending "priority": "high" instead of the required integer value like "priority": 3).

 

Troubleshooting Tips

  1. Review the Error Message: ItemPath typically returns a specific error message alongside the 400 status code. Check the Logs in ItemPath or create a report of recent API errors.
    • Tip: If you are using an automated script and can't see the response, check the API Calls endpoint in ItemPath (/api/api_calls) to view a log of recent requests and their specific error details.
  2. Validate Your Syntax: Copy your JSON body and paste it into a free online JSON Validator or JSON Lint tool. These tools will highlight exactly where a missing comma or bracket is located.
  3. Cross-Reference the Documentation Ensure your JSON matches the requirements for the specific resource you are hitting:
  4. Check for Hidden Characters If you are copying data from an Excel sheet or a PDF, hidden formatting characters can sometimes sneak into your JSON strings. Try re-typing the values manually or using a "Paste as Plain Text" option.