# Internal server error setting tags via the api

**URL:** https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137
**Category:** Support
**Created:** [October 22, 2018, 6:37am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137 "2018-10-22T06:37:04Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Akki9326](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Akki9326](https://meta.discourse.org/u/Akki9326)
#### Post date: [October 22, 2018, 6:37am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/1 "2018-10-22T06:37:04Z")

</div>

We are getting below error while posting creating topic using API. sometimes its working but most of the time is shows below error.

```
Started POST "/posts.json?api_key=[FILTERED]&amp;username=saroj.barad&amp;title=Test%20%20From%20saroj&amp;category=7&amp;raw=Test%20%20From%20saroj&amp;tags%5B%5D=law&amp;tags%5B%5D=randomnewtag" for 127.0.0.1 at 2018-10-22 06:31:44 +0000

Processing by PostsController#create as JSON

Parameters: {"api_key"=&gt;"[FILTERED]", "username"=&gt;"saroj.barad", "title"=&gt;"Test From saroj", "category"=&gt;"7", "raw"=&gt;"Test From saroj", "tags"=&gt;["law", "randomnewtag"]}

Can't verify CSRF token authenticity.

Completed 500 Internal Server Error in 124ms (ActiveRecord: 8.8ms)

NoMethodError (undefined method `&gt;' for nil:NilClass)

/var/www/discourse/lib/discourse_tagging.rb:58:in `tag_topic_by_names'

Started POST "/posts.json" for 127.0.0.1 at 2018-10-22 06:32:27 +0000

Processing by PostsController#create as JSON

Parameters: {"title"=&gt;"Test from saroj", "category"=&gt;"7", "tags"=&gt;["finance"], "api_key"=&gt;"[FILTERED]", "api_username"=&gt;"saroj.barad", "raw"=&gt;"Test from saroj "}

Completed 500 Internal Server Error in 200ms (ActiveRecord: 8.0ms)

NoMethodError (undefined method `&gt;' for nil:NilClass)

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 22, 2018, 6:42am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/2 "2018-10-22T06:42:31Z")

</div>

See:

> [@Reverse engineer the Discourse API](https://meta.discourse.org/t/how-to-reverse-engineer-the-discourse-api/20576):
>
> Discourse is backed by a complete JSON api. Anything you can do on the site you can also do using the JSON api. The API is documented at [docs.discourse.org](https://docs.discourse.org). You can also use the [discourse\_api](https://github.com/discourse/discourse_api) Ruby gem as a client library. However, not every endpoint is documented. To determine how to do something with the JSON API here are some steps you can follow. Example: recategorize a topic. Go to a topic and start editing a category: Open Chrome dev tools, switch to the Network tab, select …

Attempt to change tags on a topic, looks at the param.

---

<div class="post-metadata">

### Author: ![Akki9326](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Akki9326](https://meta.discourse.org/u/Akki9326)
#### Post date: [October 22, 2018, 7:16am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/3 "2018-10-22T07:16:34Z")

</div>

does discourse need X-CSRF-TOKEN?  
if we pass “api key”. bcz we are sending api key in our request still it shows `"Can’t verify CSRF token authentiity"`.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 22, 2018, 7:24am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/4 "2018-10-22T07:24:06Z")

</div>

That error is not related.

---

<div class="post-metadata">

### Author: ![Akki9326](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Akki9326](https://meta.discourse.org/u/Akki9326)
#### Post date: [October 22, 2018, 10:11am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/5 "2018-10-22T10:11:15Z")

</div>

Thanks for your replies. But we are also getting 500 error code while creating topic from discourse portal.

```
Started POST "/posts" for 127.0.0.1 at 2018-10-22 10:08:19 +0000
Processing by PostsController#create as JSON
Processing by Presence::PresencesController#publish as */*
Parameters: {"previous"=&gt;""}
Parameters: {"raw"=&gt;"Good post", "title"=&gt;"How does the Membership functionality work", "unlist_topic"=&gt;"false", "category"=&gt;"7", "is_warning"=&gt;"false", "archetype"=&gt;"regular", "typing_duration_msecs"=&gt;"6200", "composer_open_duration_msecs"=&gt;"179956", "shared_draft"=&gt;"false", "nested_post"=&gt;"true"}
Completed 200 OK in 10ms (Views: 0.2ms | ActiveRecord: 3.0ms)
Completed 500 Internal Server Error in 59ms (ActiveRecord: 9.6ms)
NoMethodError (undefined method `&gt;' for nil:NilClass)
/var/www/discourse/lib/topic_creator.rb:161:in `setup_tags'

```

Please help me with this.

---

<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: [October 22, 2018, 10:57am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/8 "2018-10-22T10:57:30Z")

</div>

Hi @Akki9326, it looks like we have a bug here. To work around it for now, open up the preferences for the category, and set the “Minimum number of tags required in a topic” setting to zero.

We will look at getting this fixed so it can’t happen in the future.

---

<div class="post-metadata">

### Author: ![Akki9326](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Akki9326](https://meta.discourse.org/u/Akki9326)
#### Post date: [October 22, 2018, 1:28pm UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/9 "2018-10-22T13:28:37Z")

</div>

Thank @david for your reply. but there is no settings like 'Minimum number of tags required in a topic".

for your info:

1. we are able to create a topic in other categories but error occurs on one specific category only named “CFO-Members”. we are able to create same topic in other categories.
2. Admin can create topic in that category (CFO-Members).

it would be greate for us if can you suggest any work around for the same.

---

<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: [October 22, 2018, 1:38pm UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/10 "2018-10-22T13:38:38Z")

</div>

> [@Akki9326](#):
>
> there is no settings like 'Minimum number of tags required in a topic".

The setting is located in the “settings” tab for each specific category (the same place that you edit the category name).

---

<div class="post-metadata">

### Author: ![Akki9326](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@Akki9326](https://meta.discourse.org/u/Akki9326)
#### Post date: [October 23, 2018, 5:26am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/11 "2018-10-23T05:26:36Z")

</div>

Thanks @david its works. 🙂

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 22, 2018, 9:21am UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/14 "2018-11-22T09:21:03Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

---

<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: [November 29, 2018, 5:12pm UTC](https://meta.discourse.org/t/internal-server-error-setting-tags-via-the-api/100137/15 "2018-11-29T17:12:44Z")

</div>

For future reference, this is now fixed thanks to @maja

[https://github.com/discourse/discourse/commit/4a8f21d38743a0a6b2a161889e335581248583b9](https://github.com/discourse/discourse/commit/4a8f21d38743a0a6b2a161889e335581248583b9)
