CMS Development

Brayn
Teilnehmer/-in

About Access to Published HubDB Table

Hi,

 

I have a question about tables in HubDB. Who can access a published table and how? There are warnings about this, but I'm not sure what they mean.

 

When you publish a table, HubSpot warns you that "Publishing your HubDB table will make all of the information stored in the table public and accessible to anyone via the public API," which sounds like anyone in the world can fetch data from your table. In the documentation, it says "When a table is published, it becomes public and it can be queried from unauthenticated APIs such as HubL tags and functions." This makes it sound like, in addition to being accessible by the authenticated REST API,  the table can also be accessed from web pages in HubSpot (but only there, since HubL runs there). It is unclear to me whether this means HubL in your own pages or anyone's pages on HubSpot.

 

What exactly do these warnings mean?

 

Thanks for any information,

Bryan

0 Upvotes
1 Antwort
lscanlan
HubSpot-Alumnus/Alumna
HubSpot-Alumnus/Alumna

About Access to Published HubDB Table

Hi @Brayn,

 

I'll clarify a few things here. You're right that the table data can be accessed publicly once the table is published. But this is done via the public REST API, not actually through HubL. With HubL it's only possible to use those functions to pull data from your own account. So for example using the hubdb_table(), hubdb_table_column(), hubdb_table_row(), hubdb_table_rows() functions, you can only pull data from the tables within your own account.

 

But the table data is accessible through the REST API without authentication, provided that you include the account ID (portalId) in the request URL. So here's an example of a table from my own account that you can pull through the API without authenticating the request: https://api.hubapi.com/hubdb/api/v2/tables/1575412/rows?portalId=437004. Since you're incuding the portalId, you should get a response with the table data in the body.

 

You can also make that same request from a web page. Here's some sample JS that you can paste into the console of a page, and it should log out the results:

 

fetch('https://api.hubapi.com/hubdb/api/v2/tables/1575412/rows?portalId=437004')
  .then(
    function(response) {
      if (response.status !== 200) {
        console.log('Looks like there was a problem. Status Code: ' +
          response.status);
        return;
      }

      // Examine the text in the response
      response.json().then(function(data) {
        console.log(data);
      });
    }
  )
  .catch(function(err) {
    console.log('Fetch Error :-S', err);
  });

 

Let me know if that clears things up or if you have any questions.

Leland Scanlan

HubSpot Developer Support
0 Upvotes