APIs & Integrations

JeffreyPia
Member

Retrieving mots popular posts via API

SOLVE

Hi folks,

Need some guidance figuring out a solution for this task:

I have a Wordpress blog that uses Hubspot for tracking purposes. My colleague has an account that can access the Analytics. I would like to use an API endpoint (via Javascript or PHP) to return the most popular 6(-ish) posts (URLs are fine), maybe within a date timeframe. I would then use that info to query WordPress and display the respective post content per client request. Ideally I would run this query just once per day, and cache the results.

 

I have tried creating a dev account, but I'm not sure if it being tied to my account would work, or if it needs to be created from my colleague's account. Just not sure what the next steps should be, so any assistance would be greatly appreciated!

 

Posted this originally in the CMS Development forum, but realized this it was probably better suited to this forum.

 

Thanks in advance,

Jeff

0 Upvotes
1 Accepted solution
JasminLin
Solution
HubSpot Employee
HubSpot Employee

Retrieving mots popular posts via API

SOLVE

Hi @JeffreyPia , to pull the most popular posts tracked in HubSpot, assuming popular means the highest number of views, the endpoint you can use is this https://developers.hubspot.com/docs/methods/analytics/get-analytics-data-by-object. The object_type should be pages and you can add query params as filters to the endpoint e.g. &sort=rawViews. 

 

In order to use the endpoint to get the data from the portal your colleague has access to, the authentication needed in the endpoint is either a hapikey or OAuth access token. Hapikey can be obtained from the portal - see here. For OAuth you will need a developer portal to create an app, then install the app on the portal for it to work - more info here. So depending on how you are looking to develop the solution, either way would work. 

View solution in original post

3 Replies 3
JasminLin
Solution
HubSpot Employee
HubSpot Employee

Retrieving mots popular posts via API

SOLVE

Hi @JeffreyPia , to pull the most popular posts tracked in HubSpot, assuming popular means the highest number of views, the endpoint you can use is this https://developers.hubspot.com/docs/methods/analytics/get-analytics-data-by-object. The object_type should be pages and you can add query params as filters to the endpoint e.g. &sort=rawViews. 

 

In order to use the endpoint to get the data from the portal your colleague has access to, the authentication needed in the endpoint is either a hapikey or OAuth access token. Hapikey can be obtained from the portal - see here. For OAuth you will need a developer portal to create an app, then install the app on the portal for it to work - more info here. So depending on how you are looking to develop the solution, either way would work. 

JeffreyPia
Member

Retrieving mots popular posts via API

SOLVE

Hi Jasmin,

Thanks for getting back to me! Yes, I believe that endpoint should be a good start, especially w/ the param for time_period. I intend to use PHP and cURL the data in once per day. Think the hapikey should suffice for that?

 

The authentication part is where I was getting confused. Is it as simple as implementing within the endpoint url?
i.e. do a cURL to /analytics/v2/reports/pages/[time_period]?hapikey=[hapikey]&[additional parms]
https://developers.hubspot.com/docs/methods/auth/oauth-overview

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Retrieving mots popular posts via API

SOLVE

Hey, @JeffreyPia.

 

Yep, you can certainly use your account's API key for a daily fetch.

 

If you use the API key, then all you have to do is append it to your request URL with the hapikey parameter, as you have shown!

Isaac Takushi

Associate Certification Manager
0 Upvotes