AstonJ
(AstonJ)
06.Июль.2020 03:31:54
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 лайка
fzngagan
(Faizaan Gagan)
06.Июль.2020 07:15:26
2
Maybe make it tags:["testtag"]
2 лайка
AstonJ
(AstonJ)
06.Июль.2020 15:11:40
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)
06.Июль.2020 15:14:40
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 лайк
AstonJ
(AstonJ)
06.Июль.2020 15:17:40
5
It needs this format:
But how to do that with the gem?
fzngagan
(Faizaan Gagan)
06.Июль.2020 15:34:21
6
This is what I illustrated in my above post.
fzngagan
(Faizaan Gagan)
06.Июль.2020 15:44:55
8
Can you try some other tags?
1 лайк
AstonJ
(AstonJ)
06.Июль.2020 15:47:19
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 лайк
fzngagan
(Faizaan Gagan)
06.Июль.2020 15:57:53
10
Can you turn off required tags on a category to see whether the thing actually works?
AstonJ
(AstonJ)
06.Июль.2020 16:37:59
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 лайк
fzngagan
(Faizaan Gagan)
06.Июль.2020 16:40:18
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 лайк
blake
(Blake Erickson)
06.Июль.2020 16:42:54
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 лайков
blake
(Blake Erickson)
09.Июль.2020 18:53:39
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 лайка
AstonJ
(AstonJ)
09.Июль.2020 22:03:09
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 лайка
blake
(Blake Erickson)
Закрыл(а) тему
11.Июль.2020 00:00:08
17
This topic was automatically closed after 29 hours. New replies are no longer allowed.