APIs & Integrations

JGallup
Member

Get Recent Blog Posts using v3 of HubSpot API

SOLVE

Hello!

 

I'm attempting to update some old legacy code using v2 of the HubSpot API to v3 with the new Private App authentication. In doing this I have to update a call to gather recent blog posts. With v2 of the API I used the following call and was able to get the 5 most recent blog posts:

https://api.hubapi.com/content/api/v2/blog-posts?hapikey=<--HUBSPOT API KEY -->&limit=5&state=PUBLISHED

 

How do I do this with v3? So far I have the following call, but it only returns published posts from the beginning of time (when we started posting blog posts):

https://api.hubapi.com/cms/v3/blogs/posts?createdAt__lte=2022-11-29&sort=createdAt&limit=5&state=PUBLISHED

 

Thank you for any help you can provide!

-Jon

0 Upvotes
1 Accepted solution
skimura
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

Get Recent Blog Posts using v3 of HubSpot API

SOLVE

@JGallup 

 

Hi.

 

How about this?(change query 'sort=createdAt' → 'sort=-created' )

https://api.hubapi.com/cms/v3/blogs/posts?createdAt__lte=2022-11-29&sort=-created&limit=5&state=PUBLISHED

 

https://developers.hubspot.com/docs/api/cms/blog-post#sorting-and-paginating

"You can provide sorting and pagination options as query parameters. Specify the property name as the value to the sort query parameter to return the blog posts in the natural order of that property. You can reverse the sorting order by including a dash character before the property name (e.g., sort=-createdAt)."

 

Thanks.

View solution in original post

0 Upvotes
2 Replies 2
skimura
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

Get Recent Blog Posts using v3 of HubSpot API

SOLVE

@JGallup 

 

Hi.

 

How about this?(change query 'sort=createdAt' → 'sort=-created' )

https://api.hubapi.com/cms/v3/blogs/posts?createdAt__lte=2022-11-29&sort=-created&limit=5&state=PUBLISHED

 

https://developers.hubspot.com/docs/api/cms/blog-post#sorting-and-paginating

"You can provide sorting and pagination options as query parameters. Specify the property name as the value to the sort query parameter to return the blog posts in the natural order of that property. You can reverse the sorting order by including a dash character before the property name (e.g., sort=-createdAt)."

 

Thanks.

0 Upvotes
JGallup
Member

Get Recent Blog Posts using v3 of HubSpot API

SOLVE

That was it! Thank you so much!

 

For everyone's reference, the way I'm making this work on my end is to query the Private App with the following URL to get the most recent posts:

https://api.hubapi.com/cms/v3/blogs/posts?createdAt__lte=<--tomorrows date-->&sort=-created&limit=5&state=PUBLISHED

 

This is the same URL that @skimura posted above, except I have the script writing and executing this CURL request use tomorrow's date so that it's always looking for the most recent posts and takes into account any posts that were posted today.

 

Cheers,

Jon