Cannot create topic through API

I am running discourse on my local machine. When I tried to create the topic I got the following response
{"id":24,"name":null,"username":"msriitd","avatar_template":"/user_avatar/localhost/msriitd/{size}/3_2.png","created_at":"2020-07-09T12:08:59.695Z","cooked":"\u003cp\u003eAnything above the 20 characters\u003c/p\u003e","post_number":6,"post_type":1,"updated_at":"2020-07-09T12:08:59.990Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"incoming_link_count":0,"reads":0,"readers_count":0,"score":0,"yours":true,"topic_id":3,"topic_slug":"about-the-lounge-category","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":1,"can_edit":true,"can_delete":true,"can_recover":false,"can_wiki":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":8,"can_act":true},{"id":7,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"draft_sequence":5,"hidden":false,"trust_level":1,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"reviewable_id":null,"reviewable_score_count":0,"reviewable_score_pending_count":0}

I think the topic is created but I cannot see in my UI. Can someone tell me what I am doing wrong here.

Can you share the request which you’re using to create the topic? One possibility is that you’re creating a personal message rather than a regular topic?

topic := Topic{Title: title, TopicID: topicId, Raw: raw, Category: category, CreatedAt: createdAt}

	jsonReq, err := json.Marshal(topic)
	if err != nil {
		fmt.Println(err)
	}

	req, err := http.NewRequest("POST", "http://localhost:3000/posts.json", bytes.NewBuffer(jsonReq))
	req.Header.Set("Api-Key", "key")
	req.Header.Set("Api-Username", "user")
	req.Header.Set("Content-Type", "application/json; charset=utf-8")
client := http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatalln(err)
	}

	b, err := ioutil.ReadAll(resp.Body)
	fmt.Println(string(b))

When creating a topic you can leave off the topic_id. topic_id is only needed when creating a post on an existing topic.

It looks like you are creating a post on an existing topic though and not a new topic. You can browse to it directly to see why maybe it isn’t showing up in the feed /t/about-the-lounge-category/3.

If you are not logged in you will not be able to see the post because it is in the private lounge category.

4 Likes