CMS Development

matteo
Member

API Blog listing based on tag

SOLVE

Hi everyone,

 

we are implelenting a blog stream in a client's website therefore we are using API cURL call 

 

https://api.hubapi.com/content/api/v2/blog-posts?hapikey=demo&updated__gt=1430452800000&content_group_id=351076

 

we are facing an issue: blog post have been tagged with several tags, such as News, Events or other marketing tags.

 

what we are trying to make out is if there's a way to list ONLY posts tagged with specific single keyword such as NEWS.

 

thank you!

0 Upvotes
1 Accepted solution
tjoyce
Solution
Recognized Expert | Platinum Partner
Recognized Expert | Platinum Partner

API Blog listing based on tag

SOLVE

@matteo - Unfortuanately, you cannot query the API with a blog topic name. However, you can use the topics api endpoint to get the topics that you need to query, which will get the relative ID to that topic. Then, you can pass a parameter of topic_id= to your blog post listing API call.

example: 

https://api.hubapi.com/content/api/v2/blog-posts?hapikey=demo&topic_id=53100784


If this answer helped, please, mark as solved 😄


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

View solution in original post

0 Upvotes
tjoyce
Solution
Recognized Expert | Platinum Partner
Recognized Expert | Platinum Partner

API Blog listing based on tag

SOLVE

@matteo - Unfortuanately, you cannot query the API with a blog topic name. However, you can use the topics api endpoint to get the topics that you need to query, which will get the relative ID to that topic. Then, you can pass a parameter of topic_id= to your blog post listing API call.

example: 

https://api.hubapi.com/content/api/v2/blog-posts?hapikey=demo&topic_id=53100784


If this answer helped, please, mark as solved 😄


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

0 Upvotes
MFall13
Contributor | Platinum Partner
Contributor | Platinum Partner

API Blog listing based on tag

SOLVE

@tjoyce is it possible to pass multiple topic id values to the same topic_id query parameter? 

 

Something like &topic_id=xxxxxxxx&xxxxxxxx OR &topic_id=xxxxxxxx&topic_id=xxxxxxxx ?

0 Upvotes
tjoyce
Recognized Expert | Platinum Partner
Recognized Expert | Platinum Partner

API Blog listing based on tag

SOLVE

Hi @MFall13 - I have not tried to search multiple topics before but perhaps the double underscore query might be something you can explore... Something like

&topic_ids__in=10945,28906

However, I suspect something like this might return only posts that appear in both topics... might need some guess work done around this

 

Optional query string filters & options
Some parameters support "range" filters via double-underscored param suffixes, like '__gt'. If a parameter supports a filter type of 'gt', that means you can append a double-underscore and 'gt' to the parameter name to find all items greater than a specified value.

For example, the following query will find all items with the 'updated' time greater than 1364424600000: https://api.hubapi.com/blogs/v3/topics?hapikey=demo&created__gt=1364424600000
MFall13
Contributor | Platinum Partner
Contributor | Platinum Partner

API Blog listing based on tag

SOLVE

 

@tjoyce thanks for the suggestion. I feel like I've tried every value filter combo out there. 

&topic_ids__in=30111149151,32404273845" (and &topic_id__in too)

returns 

Invalid query Filtering by \"topic_id(s) in\" is not allowed

 

... another try with the following exact params:

&topic_id=30111149151&topic_id=32404273845

responds with a valid request, but only pulls in blogs with the first topic id

 

...and another try with the suffix '__contains' to no avail.

 

Any other suggestions? Much appreciated!

 

0 Upvotes