调用Debitoor /api/sales/draftinvoices/v3接口返回400错误,请求排查
Hey Jan, let's dig into that schema-related 400 error you're hitting with the Debitoor draft invoice API. Schema issues almost always come down to missing required fields, incorrect data types, or formatting mismatches—here are the most common culprits to check off first:
Double-check all required fields are present
Debitoor's v3 draft invoice endpoint has non-negotiable required fields like
contactId,lineItems, andcurrencyCode. Even one missing required field will trigger a schema error. For example,lineItemscan't be an empty array, and each line item needs at minimumdescription,quantity, andunitPrice.Fix data type mismatches
This is the #1 cause of schema errors I see. Watch out for these common mistakes:- Sending a string (like
"2") instead of an integer forquantity - Wrapping
unitPricein quotes (it needs to be a numeric value, not a string) - Passing
contactIdas a number instead of a string (Debitoor uses string-based IDs for most resources) - Using string values like
"true"instead of actual booleantrue/falsefor fields likeisVatIncluded
- Sending a string (like
Validate date formats
If you're including dates (e.g.,issueDate,dueDate), Debitoor requires ISO 8601 format—thinkYYYY-MM-DDfor dates, or full ISO timestamps if you're using datetime values. Formats like05/10/2024will break the schema validation immediately.Verify nested object structure
Fields likelineItemsorvatRateare nested objects/arrays that need to follow the exact schema structure. For example, if you're specifying a VAT rate for a line item, thevatRateobject must include bothid(string) andrate(number) properties—you can't skip either.Inspect the full error response details
Debitoor's 400 responses usually include a detailederrorsarray that tells you exactly which field is causing the problem. In your PHP script, you can decode this to get specific clues:$response = curl_exec($yourCurlHandle); $errorData = json_decode($response, true); print_r($errorData['errors']);This will output something like
"contactId is a required field"or"unitPrice must be a numeric value", which cuts straight to the issue.Pre-validate your payload with a JSON schema tool
Before sending your request, paste your JSON payload into a JSON schema validator (you can use a local tool or a simple web-based one) and compare it against Debitoor's published schema for the draft invoice endpoint. This will catch subtle formatting issues your eye might miss.
If you can share the specific error message from the response or a redacted version of your payload, I can help narrow it down even further—but these checks should cover most schema-related 400s you might be facing.
内容的提问来源于stack exchange,提问作者Jan

