Internal server error setting tags via the api


(Akash Soni) #1

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]&username=saroj.barad&title=Test%20%20From%20saroj&category=7&raw=Test%20%20From%20saroj&tags%5B%5D=law&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"=>"[FILTERED]", "username"=>"saroj.barad", "title"=>"Test From saroj", "category"=>"7", "raw"=>"Test From saroj", "tags"=>["law", "randomnewtag"]}

Can't verify CSRF token authenticity.

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

NoMethodError (undefined method `>' 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"=>"Test from saroj", "category"=>"7", "tags"=>["finance"], "api_key"=>"[FILTERED]", "api_username"=>"saroj.barad", "raw"=>"Test from saroj "}

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

NoMethodError (undefined method `>' for nil:NilClass)

(Sam Saffron) #2

See:

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


(Akash Soni) #3

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".


(Sam Saffron) #4

That error is not related.


(Akash Soni) #5

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"=>""}
Parameters: {"raw"=>"Good post", "title"=>"How does the Membership functionality work", "unlist_topic"=>"false", "category"=>"7", "is_warning"=>"false", "archetype"=>"regular", "typing_duration_msecs"=>"6200", "composer_open_duration_msecs"=>"179956", "shared_draft"=>"false", "nested_post"=>"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 `>' for nil:NilClass)
/var/www/discourse/lib/topic_creator.rb:161:in `setup_tags'

Please help me with this.


(David Taylor) #8

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.


(Akash Soni) #9

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.


(David Taylor) #10

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


(Akash Soni) #11

Thanks @david its works. :slight_smile:


(Akash Soni) #12

@david could you please help me in one more issue?
I am facing an issue while replying to a topic via APIs.

actual issue is:
when any user has created a topic and in seconds of time if I will try to reply that topic discourse give me an error “Something has gone wrong. perhaps this topic was closed or deleted while you were looking at it”.

but If I will post reply after sometime then it is working as expected.

can you please let me know how I can trace this issue?


(David Taylor) #13

Are you waiting for the original request to complete before making the second web request?

Maybe if you post a sample of your code here someone might be able to help out?