I get a 422 response when calling the create post API

Hi Discourse,

I’m pretty new to this platform, I like the way it looks and I’ve noticed some neat features so far. Cool!

I’m trying to to integrate a Discourse installation with another system, and I’m starting off by trying to create a new post by calling the API. Right now I get this response:

{
"action": "create_post",
"errors":[
"Title can't be blank",
"Title is too short (minimum is 15 characters)",
"Title seems unclear, is it a complete sentence?"
]
}

when I do this POST:

https://forum.myDomain.com/posts.json?api_key=someApiKey&api_username=someUser

with this data:

{
  "title": "This is a test title for an assignment.",
  "raw": "This is a test post for an assignment.",
  "category": 1,
  "created_at": "2018-12-17"
}

So, it seems my title is not blank, greater than 15 characters, and it’s a complete sentence. So how I am supposed to deal with this 422?

Thanks,
Ben

Oh…I just noticed that I had content-type set to URL encoded, and because I had no URL parameter specifying the title, it was causing that 422 response. I’m sorry for my post!

Using URL encoded seems to work fine for me, but I haven’t gotten multipart form data to work yet.

3 Likes