422 fout bij het plaatsen van een nieuw onderwerp via API

AI-generated summary

John_Streeter is encountering a 422 error when attempting to create a new topic via the API using multipart/form-data, receiving validation errors such as “Title can’t be blank” and “Category can’t be blank” despite providing values. The request body includes a title, raw content, category ID, display username, and created_at timestamp. blake suggests the issue may stem from improperly formatted data — specifically, sending JSON instead of actual form-data — and provides a working curl example using -F flags to send form fields correctly. The example shows proper usage of multipart/form-data with headers for Api-Key and Api-Username, and form fields for title and raw content. The root cause appears to be a mismatch between expected form-data encoding and the actual payload structure being sent, which prevents the API from parsing the fields correctly. Correcting the request format to match the curl example should resolve the 422 error.

Hi all, I’m trying to post a new topic via the API but keep getting the 422 error with the below message whenever I try to use plain text (rather than a form):

        "**action**": "create_post",
        "**errors***":[
        "Title can't be blank",
        "Title is too short (minimum is 5 characters)",
        "Title seems unclear, most of the words contain the same letters over and over?",
        "Category can't be blank"

Here’s the body:

    {
    "title": "Cannot Add Custom Rate for Retainer Rate",
    "raw":"hi",
    category":22,
    "displayusername": "nickclark",
    "created_at":"2020-12-17"
    }

I’m using content-type = multipart/form-data … is that the problem? what should I be using?

Thanks for the help!

When using the api and you see errors like “Title can’t be blank” but it looks you are actually passing in a title, this usually means that something isn’t sent to the api in the proper form and it isn’t able to read the data you are sending it. Are you sending it json instead of actual form-data?

Here is an example curl request to create a topic:

curl -i -sS -X POST "http://localhost:3000/posts.json"  \
-H "Content-Type: multipart/form-data;"  \
-H "Api-Key: 079fb2bb12d3b436bb11bde8eb58aaa9a36560fa7d79b14b3087aa40b1ebc2c4"  \
-H "Api-Username: blake.erickson"  \
-F "title=94214157b89 b723d7bc93f f40ec06495c"  \
-F "raw=e65c9465ca693efc7b676ce4d236a6a6 1978ce887069fd2b3dbd67422f151823 fcb471fe25bae2d9f2889de60edbd06b"

HTTP/1.1 200 OK