Cannot get latest posts via json (/posts.json returns 500 error)

Hey guys. I’m trying to get latest posts with help of Discourse Api gem.
I’ve added next lines to my initializer:

module DiscourseApi
  module API
    module Posts
      def latest_posts(params = {})
        response = get('/posts', params)
        response[:body]['latest_posts']
      end
    end
  end
end

On Friday everything worked fine, I was able to get latest posts. But now it responses with 500 status

Any errors in the logs?

This is all information I can get from my side, cause cannot access logs right now. Hopefully i will in several hours. Will let you know then. Thanks

Hey Sam, finally got logs from our instance:

Started GET "/posts.json" for 162.158.102.26 at 2015-12-14 21:17:01 +0000
Processing by PostsController#latest as JSON
Completed 500 Internal Server Error in 102ms (ActiveRecord: 15.6ms)
NoMethodError (undefined method `title' for nil:NilClass)
/var/www/discourse/app/serializers/post_serializer.rb:93:in `topic_title'

2 Likes

Fixed the issue by deleting the post with the absent topic.

1 Like