Skip to content

Conversation

@thomasrossetto
Copy link
Contributor

Hi,
According to the Discourse docs, I have added external_id to the list of supported options for topic creation.

@thomasrossetto
Copy link
Contributor Author

Ops, I forgot to assign reviewers :( @oblakeerickson

@blake-discourse
Copy link
Contributor

@thomasrossetto awesome thank you!

Looks like there is a small linting error.

Not sure if you have stree locally, but you can run stree write lib/discourse_api/api/topics.rb and it will fix it.

If not the diff looks like this

diff --git a/lib/discourse_api/api/topics.rb b/lib/discourse_api/api/topics.rb
index a92c398..944deb3 100644
--- a/lib/discourse_api/api/topics.rb
+++ b/lib/discourse_api/api/topics.rb
@@ -11,7 +11,15 @@ module DiscourseApi
           API
             .params(args)
             .required(:title, :raw)
-            .optional(:skip_validations, :category, :auto_track, :created_at, :api_username, :tags, :external_id)
+            .optional(
+              :skip_validations,
+              :category,
+              :auto_track,
+              :created_at,
+              :api_username,
+              :tags,
+              :external_id,
+            )
         post("/posts", args.to_h)
       end

And could you add a test? I think it can look similar to this tags one:

  describe "#create_topic_with_tags" do
    before do
      stub_post("#{host}/posts").to_return(
        body: fixture("create_topic_with_tags.json"),
        headers: {
          content_type: "application/json",
        },
      )
    end

    it "makes the post request" do
      client.create_topic title: "Sample Topic Title",
                          raw: "Sample topic content body",
                          tags: %w[asdf fdsa]
      expect(a_post("#{host}/posts")).to have_been_made
    end

    it "returns success" do
      response =
        client.create_topic title: "Sample Topic Title",
                            raw: "Sample topic content body",
                            tags: %w[asdf fdsa]
      expect(response).to be_a Hash
      expect(response["topic_id"]).to eq 21
    end
  end

So you might need to make a new fixture, and then in your expect check for the external_id in your response (I'm pretty sure its returned).

@blake-discourse
Copy link
Contributor

@thomasrossetto just checking in if you need any help? Would love to get this in. There are just some small updates we need to make.

@thomasrossetto
Copy link
Contributor Author

Sorry @blake-discourse! I’ll try to get this done in the next few days 😉

@thomasrossetto
Copy link
Contributor Author

I decided to take a quick look just now. Formatting looks fine now.

About testing: if you provide an external ID, it doesn’t appear in the response. But I’ve implemented this API
to resolve the correct URL. You can find the logic in my last commit.

I can add a test for it if you think it’s necessary.

Copy link
Contributor

@blake-discourse blake-discourse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@blake-discourse blake-discourse merged commit 969f360 into discourse:main Dec 2, 2025
7 checks passed
@blake-discourse
Copy link
Contributor

@thomasrossetto there is a new gem version now with your change https://rubygems.org/gems/discourse_api/versions/2.1.0 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants