How to Display Page Titles from HubSpot on Your Joomla Website

This weekend we had a very interesting task. We were told, by one of our top clients, to display a list of all their Pages from HubSpot, along with a link to them. As usual, we obliged, and we were glad that they gave us this task, because it was something that we haven’t done before.

The first thing that we needed to do was to get used to and understand HubSpot‘s API – which we first thought would only work after creating a HubSpot application – but we later discovered that this wasn’t needed. All that we needed to do was the following:

  • Create an API key on HubSpot which can be used to authenticate the API requests. A HubSpot API key can be acquired from this link (note that you must be logged in to HubSpot before visiting that link).
  • Grab all the pages from HubSpot using the COS Page Publishing API.

  • Filter the pages (according to client-specific requirements that we won’t mention here).

  • Display these pages in a module on the website’s homepage.

Of course, the above steps are definitely not exhaustive, but they are the main steps.

So, what was the code that we used to grab the data?

We grabbed the data using the following PHP function (which we placed in a newly created module called mod_hubspot):

function getHubSpotPages($apiKey){
	$hubSpotJson = file_get_contents(''.$apiKey);
	$data = json_decode($hubSpotJson,true);
	$hubSpotList = array();
	if (isset($data['objects'])){
		$data = $data['objects'];
		for ($i =0; $i < count($data); $i++){
			$item = new stdClass();
			$hubSpotList[$i]= $item;
			$hubSpotList[$i]->link = $data[$i]['published_url'];
			$hubSpotList[$i]->title = $data[$i]['name'];
	return $hubSpotList;

The above function returned an array of HubSpot pages, where each page consists of a title and a link. Of course, we could have retrieved more information, but that’s what our client wanted. Note that the $apiKey parameter should be the HubSpot API Key created in the first step above.

What was really impressive for us is that the above function worked quickly, very quickly. It didn’t delay the page loading at all, but we decided anyway to cache the module’s results for a whole day – just in case (we don’t like surprises that are caused by a sudden under-performance of a 3rd party application).

If you want to grab data from HubSpot and display it on your Joomla website, then the above should be very helpful. If you need more help, then we are ready to help! Just contact us and let us know your requirements, and we will surely implement them for you quickly and for a very affordable fee.

No comments yet.

Leave a comment