APIs & Integrations


Posts API with date range

Hi there, 


I'm currently building out an integration with the Blog Posts API V3 and want to retrieve posts within a date range. Using the `GET /posts` endpoint and the `publishDate__gte`, `publishDate__lte` filters (they work individually) cause zero posts to be returned even though I can see there are posts published within this date range.


It's also unclear from the documentation what the correct format for the `publishDate` value. Below are what I've seen online. I'm currently using the unix timestamp.

* Unix timestamp in milliseconds

* Date string. i.e. `YYYY-MM-DD`

* ISO8601 timestamp. i.e. `YYYY-MM-DDTHH:MM:SS.000Z`


Below are some queries I'm using to demonstrate this behavior:


# WORKS (publishDate__gte)
GET https://api.hubapi.com/cms/v3/blogs/posts?offset=0&limit=10&publishDate__gte=1682899200000&state=PUBLISHED

# WORKS (publish_date__lte)
GET https://api.hubapi.com/cms/v3/blogs/posts?offset=0&publishDate__lte=1685577600000&limit=10&state=PUBLISHED

# FAILS (publishDate__gte & publishDate__lte)
GET https://api.hubapi.com/cms/v3/blogs/posts?publishDate__lte=1685577600000&limit=10&publishDate__gte=1680739200000&offset=0&state=PUBLISHED

 Any guidance would be appreciated, thanks!

2 Replies 2

Posts API with date range

Hi Jaycee,


Thanks for looking into it! You are correct, I was assuming the API would accept two dates and return posts between those dates. I don't know the specifics of the implementation but hoped/assumed it would take unique "<field>__<opr>" params then AND them together generating the effect I'm looking for. (fairly common pattern for DBs, etc.)


If there's anymore info I can provide please let me know!

Community Manager
Community Manager

Posts API with date range

Hi, @chason-choate 👋 Thank you for the interesting question! You have found a use case that I cannot find documentation. That's not a bad thing, it helps all of us to ask questions like this. 


Please correct me if I am misunderstanding, but it sounds like you are trying to use these filters in combination in the same or similar manner as we use the BETWEEN search operator in the Search API. That operator accepts a high value and value to set the range to include or exclude dates. 


While the documentation you linked indicates we can add multiple filters to a query, what's not clear is if we can use the two specific filters you are using in the manner you want to use them. My gut says this is working as designed, but not like you want. 


I'm going to do some research and ask my internal resources. If I get us any clarity, I'll add it here. 





Jaycee Lewis

Developer Community Manager

Community | HubSpot