# Get last n new / updated posts using API?

**URL:** https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427
**Category:** Development
**Tags:** rest-api
**Created:** [May 9, 2024, 4:16pm UTC](https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427 "2024-05-09T16:16:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Samir\_Sabri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samir_sabri/32/287380_2.png) [@Samir\_Sabri](https://meta.discourse.org/u/Samir_Sabri)
#### Post date: [May 9, 2024, 4:16pm UTC](https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427/1 "2024-05-09T16:16:06Z")

</div>

Hello

I tried to use APIs to get last n posts using

```plaintext
uri = URI('https://mydomain.com/forum/latest.json?ascending=false')

```

however, I noticed the following:

- could not have the URL of each post
- could not strict result to last n posts.
- how to restrict returned fields ? ex: I am getting all details currently.

Any idea ?

---

<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: [May 9, 2024, 4:57pm UTC](https://meta.discourse.org/t/get-last-n-new-updated-posts-using-api/307427/2 "2024-05-09T16:57:51Z")

</div>

> [@Samir\_Sabri](#):
>
> I tried to use APIs to get last n posts using

Are you trying to get the last n posts or the last n topics?

`/latest.json` will give you the latest topics

`/posts.json` will give you the latest posts across all topics.

> [@Samir\_Sabri](#):
>
> could not have the URL of each post

The URLs you can just construct from the results based off of the topic\_id or post\_id.

For example a valid url for this topic is: [https://meta.discourse.org/t/307427](https://meta.discourse.org/t/307427) and for the post would be [https://meta.discourse.org/p/1514266](https://meta.discourse.org/p/1514266).

> [@Samir\_Sabri](#):
>
> could not strict result to last n posts.

There isn’t a way to change the default page size of 30. If you really really want less than 30 you have pass in the specific topic ids:

[https://meta.discourse.org/latest.json?topic\_ids[]=307427](https://meta.discourse.org/latest.json?topic_ids%5B%5D=307427)

But you would have to know what those topic ids are beforehand so not really all that helpful usually. If you want more than 30 you will have to make multiple requests and pass in the `page` parm.

[https://meta.discourse.org/latest.json?page=1](https://meta.discourse.org/latest.json?page=1)

> [@Samir\_Sabri](#):
>
> how to restrict returned fields ? ex: I am getting all details currently.

You can’t, you will have to filter them out from the results yourself.

> [@Samir\_Sabri](#):
>
> `?ascending=false`

This is the default, so you don’t have to specify `ascending=false`, you can just leave this off.
