422 error when posting new topic via API

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",
        "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",
    "displayusername": "nickclark",

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

Thanks for the help!

1 Like

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