Discourse API Gem - how to create topic with tags?

This isn’t working…

client.create_topic(
  title: "My Title",
  category: "13",
  raw: "My Post",
  tags: "testtag"
)

Since we require at last one tag, I get:

DiscourseApi::UnprocessableEntity ({"action"=>"create_post", "errors"=>["You must select at least 1 tag."]}):

Any idea how we create topics with tags via the Discourse gem?

2 Likes

Maybe make it tags:["testtag"]

2 Likes

That doesn’t work either Faizaan (same message that a tag is required).

Not sure if this is out of date, but it seems that tags are different to the others being some sort of array type - but how do we use that via the gem?

If you look at the network tab while making a successful request, then you can translate it to how to do it with the gem.

1 Like

It needs this format:

But how to do that with the gem?

This is what I illustrated in my above post.

…but it does not work:

DiscourseApi::UnprocessableEntity ({“action”=>“create_post”, “errors”=>[“You must select at least 1 tag.”]}):

:confused:

1 Like

Can you try some other tags?

1 Like

Haha that’s what I was thinking too so just did - the last few I tried definitely exist (but still doesn’t work).

1 Like

Can you turn off required tags on a category to see whether the thing actually works?

Do you mean the gem? It works as I use it to make posts in existing topics (from the same script in fact), send PMs etc. This is the first time I am trying to add tags though…

1 Like

Ok, I see. I’m sure you are doing but just confirming

client.create_topic(
  title: "My Title",
  category: "13",
  raw: "My Post",
  tags: ["testtag", "testtag2"]
)
1 Like

Looking at the source code for the discourse_api gem it doesn’t look like it supports creating topics with tags yet. I’ll add it to my list.

5 Likes

Thanks Blake :slightly_smiling_face:

1 Like

Okay, you can create Topics with tags now using the latest version (0.42.0) of the discourse_api gem.

You just need to pass the tags in an array like so:

3 Likes

Wow - that was fast Blake!

I wasn’t expecting an update so soon and so managed to find a workaround by using the post method and passing everything as params. Doing it with create_topic is definitely better tho, thanks!

3 Likes

This topic was automatically closed after 29 hours. New replies are no longer allowed.