Get Recent Blog Posts using v3 of HubSpot API

JGallup
メンバー

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 いいね!
1件の承認済みベストアンサー
skimura
解決策
トップ投稿者 | Platinum Partner
トップ投稿者 | Platinum Partner

@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 いいね!
2件の返信 2
skimura
解決策
トップ投稿者 | Platinum Partner
トップ投稿者 | Platinum Partner

@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 いいね!
JGallup
メンバー

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