# Cannot create topic through API

**URL:** https://meta.discourse.org/t/cannot-create-topic-through-api/157255
**Category:** Support
**Created:** [July 9, 2020, 12:12pm UTC](https://meta.discourse.org/t/cannot-create-topic-through-api/157255 "2020-07-09T12:12:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Minhaj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/minhaj/32/137595_2.png) [@Minhaj](https://meta.discourse.org/u/Minhaj)
#### Post date: [July 9, 2020, 12:12pm UTC](https://meta.discourse.org/t/cannot-create-topic-through-api/157255/1 "2020-07-09T12:12:38Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [July 9, 2020, 12:17pm UTC](https://meta.discourse.org/t/cannot-create-topic-through-api/157255/2 "2020-07-09T12:17:05Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Minhaj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/minhaj/32/137595_2.png) [@Minhaj](https://meta.discourse.org/u/Minhaj)
#### Post date: [July 9, 2020, 12:18pm UTC](https://meta.discourse.org/t/cannot-create-topic-through-api/157255/3 "2020-07-09T12:18:35Z")

</div>

```
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))

```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [July 9, 2020, 10:44pm UTC](https://meta.discourse.org/t/cannot-create-topic-through-api/157255/4 "2020-07-09T22:44:07Z")

</div>

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.
