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

**URL:** https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682
**Category:** Bug
**Tags:** rest-api
**Created:** [December 14, 2015, 11:53am UTC](https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682 "2015-12-14T11:53:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ks\_smilik](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ks_smilik/32/122066_2.png) [@ks\_smilik](https://meta.discourse.org/u/ks_smilik)
#### Post date: [December 14, 2015, 11:53am UTC](https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682/1 "2015-12-14T11:53:43Z")

</div>

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

```plaintext
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  
 ![screenshot](http://take.ms/nDvCw)

---

<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: [December 14, 2015, 12:02pm UTC](https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682/2 "2015-12-14T12:02:16Z")

</div>

Any errors in the logs?

---

<div class="post-metadata">

### Author: ![ks\_smilik](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ks_smilik/32/122066_2.png) [@ks\_smilik](https://meta.discourse.org/u/ks_smilik)
#### Post date: [December 14, 2015, 12:17pm UTC](https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682/3 "2015-12-14T12:17:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ks\_smilik](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ks_smilik/32/122066_2.png) [@ks\_smilik](https://meta.discourse.org/u/ks_smilik)
#### Post date: [December 14, 2015, 9:19pm UTC](https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682/4 "2015-12-14T21:19:24Z")

</div>

Hey Sam, finally got logs from our instance:

```plaintext
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'

```

---

<div class="post-metadata">

### Author: ![ks\_smilik](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ks_smilik/32/122066_2.png) [@ks\_smilik](https://meta.discourse.org/u/ks_smilik)
#### Post date: [December 15, 2015, 9:40am UTC](https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682/5 "2015-12-15T09:40:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [December 15, 2015, 10:10am UTC](https://meta.discourse.org/t/cannot-get-latest-posts-via-json-posts-json-returns-500-error/36682/6 "2015-12-15T10:10:13Z")

</div>


