Querying Posts in a given time range via content API

Hi,

I’m currently looking for a possibility to get all Posts of a given time range via the content api. The scenarios I have in mind are the following:

  • Get all Posts from the last x days
  • Get all Posts between and
  • Get all Posts from month
  • Get all Posts older than x
  • Get all Posts younger than x

After reading the documentation does not seem to be a parameter to adjust GET Post queries in this way. Is there any other possibility than fetching all posts and doing the math ony my own?

Kind regards,
Christoph

You can use the ?filter param for that. Eg:

GET /ghost/api/v2/content/posts/?filter="published_at:>='1948-12-12 00:00:00'+published_at:<='1963-08-28 23:50:59'"

Note that dates need to wrapped in quotes inside the filter param, also make sure that everything gets url-encoded properly :slight_smile:

➜ curl https://demo.ghost.io/ghost/api/v2/content/posts/\?key\=22444f78447824223cefc48062\&\filter\="published_at:>='1948-12-12%2000:00:00'%2bpublished_at:<='1963-08-28%2023:59:59'"\&fields=title,published_at | jq
######################################################################## 100.0%
{
  "posts": [
    {
      "title": "I Have a Dream",
      "published_at": "1963-08-28T08:00:00.000+00:00"
    },
    {
      "title": "The Purpose of Education",
      "published_at": "1948-12-12T10:00:00.000+00:00"
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "limit": 15,
      "pages": 1,
      "total": 2,
      "next": null,
      "prev": null
    }
  }
}