Discourse always posts in general using API

AI-generated summary

When posting via the Discourse API, some users have encountered issues with specifying the correct category. dylanh724 initially had trouble with the category not being set correctly, despite using the correct category ID as a number. After trying different approaches, it was discovered that the category ID should be sent as a string, not a number. riking mentioned that supporting category IDs was an accident, and DeanMarkTaylor pointed out that the documentation recommends using integer category ID values. However, blake clarified that when creating a topic via the API, the category should be specified by ID, but as a string, not by name.

Whenever I post via the API, I tested it in Postman and it sends the right things to the right category.

However, when I more or less copy+paste the same thing with an http POST (via JavaScript), I get everything right…EXCEPT the category (which I thought was the easiest part):

I’m just truly stumped. Does anyone have any ideas as to why this wouldn’t send to the correct category?

  • I’m posting it as a FORM data (and not JSON, like Postman/tutorial says to do)
  • No special headers - it’s pretty vanilla
  • I copy+pasted “category” to ensure I didn’t typo it (shown in screenshot). It IS an number, right? I’m about to try it as text

UPDATE:

It IS an number, right? I’m about to try it as text

Error 422 when I try it as string. It is definitely a number.

UPDATE 2:

Wait a sec… I’m still getting 422 errors even when account is admin? I guess this is for a new post

Ahhhh apparently error 422 is rate-limiting. The category “number” IS actually “text” (a string). Making bot account admin seemed to do the trick for the limiting (…but why do I have to make it an ADMIN to edit rate limiting? Seems a bit of a dramatic upgrade for such) and “15” as the category as a string.

I believe the browser client submits the category as its name; supporting the id was an accident.

See also:

If it was an accident - that sounds a little cray-cray…

Just wanted to clarify that when creating a topic in a category via the API, you specify the category by id now, not by name.