AstonJ
(AstonJ)
July 6, 2020, 3:31am
1
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
fzngagan
(Faizaan Gagan)
July 6, 2020, 7:15am
2
Maybe make it tags:["testtag"]
2 Likes
AstonJ
(AstonJ)
July 6, 2020, 3:11pm
3
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?
This worked for me and added two tags:
curl --data "api_key=asdf...asdf&api_username=neill&title=this%20one%20has%20two%20tags&raw=and%20it%20is%20twice%20as%20delicious&tags[]=mazda&tags[]=protege" http://localhost:3000/posts.json
[image]
So I’m not sure why it isn’t working for you…
fzngagan
(Faizaan Gagan)
July 6, 2020, 3:14pm
4
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
AstonJ
(AstonJ)
July 6, 2020, 3:17pm
5
It needs this format:
But how to do that with the gem?
fzngagan
(Faizaan Gagan)
July 6, 2020, 3:34pm
6
This is what I illustrated in my above post.
fzngagan
(Faizaan Gagan)
July 6, 2020, 3:44pm
8
Can you try some other tags?
1 Like
AstonJ
(AstonJ)
July 6, 2020, 3:47pm
9
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
fzngagan
(Faizaan Gagan)
July 6, 2020, 3:57pm
10
Can you turn off required tags on a category to see whether the thing actually works?
AstonJ
(AstonJ)
July 6, 2020, 4:37pm
11
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
fzngagan
(Faizaan Gagan)
July 6, 2020, 4:40pm
12
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
blake
(Blake Erickson)
July 6, 2020, 4:42pm
13
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
blake
(Blake Erickson)
July 9, 2020, 6:53pm
15
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:
fzngagan:
client.create_topic(
title: "My Title",
category: "13",
raw: "My Post",
tags: ["testtag", "testtag2"]
)
4 Likes
AstonJ
(AstonJ)
July 9, 2020, 10:03pm
16
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
blake
(Blake Erickson)
Closed
July 11, 2020, 12:00am
17
This topic was automatically closed after 29 hours. New replies are no longer allowed.