AstonJ
(AstonJ)
6 يوليو 2020، 3:31ص
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)
6 يوليو 2020، 7:15ص
2
Maybe make it tags:["testtag"]
إعجابَين (2)
AstonJ
(AstonJ)
6 يوليو 2020، 3:11م
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)
6 يوليو 2020، 3:14م
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)
6 يوليو 2020، 3:17م
5
It needs this format:
But how to do that with the gem?
fzngagan
(Faizaan Gagan)
6 يوليو 2020، 3:34م
6
This is what I illustrated in my above post.
fzngagan
(Faizaan Gagan)
6 يوليو 2020، 3:44م
8
Can you try some other tags?
إعجاب واحد (1)
AstonJ
(AstonJ)
6 يوليو 2020، 3:47م
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)
6 يوليو 2020، 3:57م
10
Can you turn off required tags on a category to see whether the thing actually works?
AstonJ
(AstonJ)
6 يوليو 2020، 4:37م
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)
6 يوليو 2020، 4:40م
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)
6 يوليو 2020، 4:42م
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)
9 يوليو 2020، 6:53م
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)
9 يوليو 2020، 10:03م
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، 12:00ص
17
This topic was automatically closed after 29 hours. New replies are no longer allowed.