It is possible to use our own API for some HTML generation in a HubSpot blog


#1

Hi,

Currently I have several websites and they all use common APIs to get a common HTML for specific areas like the header, the footer (...). This has several positive effects from a maintainability and homogenous point of view.

Is it possible with the HubSpot solution to create a blog that uses these client APIs to return HTML code, with a retention period (to avoid too much API calls for each hits on a page )?

Best regards,
Sébastien.B


#2

@Sebastien why don't you just call your API via AJAX?


#3

@craigivemy, Because these calls should not be made for each hits on a page, it would be better if it was done for example once a week, then put in a shared cache (...) for performance reasons.
In my opinion, AJAX cross domain calls are not ideal in this case.


#4

@Sebastien is the purpose to ensure the menu items in the header and footer are kept up to date across platforms? We had similar issues whereby client WordPress sites would have the menu updated and somebody would then have to make the same edits in HubSpot - which rarely happened.

Rather than the endpoint return the HTML for the header/footer, we just return the menu item text and it's URL and add these to our existing HTML structure in HubSpot. Therefore overhead per page request is minimal.

If you want to return a chunk of HTML, perhaps use the COS templates API and run a cron job from one of your servers once a week to update the template partial (ie header or footer)


#5

@craigivemy Your suggestion necessarily implies that we host the HubSpot blog ourselves, do not we?


#6

@Sebastien not sure I understand.

I'm suggesting you create template partials in HubSpot - one for the header, one for the footer for example.

Write a script and host it somewhere outside of HubSpot that grabs the HTML from your existing APIs, then uses the HubSpot templates API to update the template partials you have created within HubSpot.

Include these template partials in your blog, and they will be updated as often as your script runs.


#7

@craigivemy Thanks for your response, but when you suggest to write a script somewhere (?) outside of HubSpot, I'm not sure to understand what you mean but this suggests that this is not possible to code something for using external API in a HubSpot blog hosted by them...
Goal of this API which generates HTML code is to avoid human action for manually updating header & footer and I know you have understood that.

My feeling is to make this blog with WordPress on our web server. By this way, we have more possibilities without use another script system just for keeping header & footer up to date.


#8

Another information, is that our API generates all HTML structure but with also texts, pictures and urls (...).
In my case, the API already returns a full template ready to use.


#9

Hi @Sebastien,

Just to chime in here; so long as your API allows for CORS requests, you should be able to make a request from your HubSpot hosted page to pull in an external HTML header. You could create a custom header module that did something like this:

<div id="external-header"></div>
<script>
$.ajax({
  url: "{{ url of your api }}",
  cache: false
})
  .done(function( html ) {
    $("#external-header").html(html);
  });
</script>

This is a super simplistic example, but I was able to get a very very basic POC up and running on a website page in my portal.