# Using the Discourse API ruby gem to post a topic as a specific user

**URL:** <https://meta.discourse.org/t/using-the-discourse-api-ruby-gem-to-post-a-topic-as-a-specific-user/98380>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [30.Сентябрь.2018 01:34:01 UTC](https://meta.discourse.org/t/using-the-discourse-api-ruby-gem-to-post-a-topic-as-a-specific-user/98380 "2018-09-30T01:34:01Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)\
**Post date:** [03.Октябрь.2018 02:12:54 UTC](https://meta.discourse.org/t/using-the-discourse-api-ruby-gem-to-post-a-topic-as-a-specific-user/98380/8 "2018-10-03T02:12:54Z")

</div>

I’ve been running it in a development environment, but just tested it in a production env. The logs don’t show for me either, but I’m able to replicate the same behavior is both env’s.

If you create a post as an admin or moderator and you specify the category as a string it does its best to guess the correct category and will work, but a regular user will hit this line

> <https://github.com/discourse/discourse/blob/main/lib/new_post_manager.rb#L95>

causing a 404 if you don’t specify the category as an id.

This works

```plaintext
topic = {
  category: 8,
  skip_validations: true,
  auto_track: false,
  title: random_string,
  api_username: "ifvhonqlmxesadwpktc",
  raw: random_string
}
new_topic = client.create_topic(topic)

```

This causes a 404:

```plaintext
topic = {
  category: "Category",
  skip_validations: true,
  auto_track: false,
  title: random_string,
  api_username: "ifvhonqlmxesadwpktc",
  raw: random_string
}
new_topic = client.create_topic(topic)

```

---

_[View the full topic](https://meta.discourse.org/t/using-the-discourse-api-ruby-gem-to-post-a-topic-as-a-specific-user/98380)._
