APIs & Integrations

tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Help converting API code to Private App code

SOLVE

We have one client that is using an API key in a custom module built by a 3rd party developer. I need to convert it to a priveate app for the Nov 30th deadline. Javascript is not one of my strong skills. I know enough to be dangerous. I have read the migration document and setting up the private app seems to be pretty straightforward. However, I need some suggestions on how to to convert the following js to utilize the private app token-

async function update() {  
  var api_key = 'xxxxxxx-xxxxxx-xxxxxx-xxxxx';
  
  fetch('https://api.hubapi.com/cms/v3/hubdb/tables/xxxxxxx/rows/draft?hapikey=' + api_key)
    .then(response => response.json())
    .then(data =>  listing_delete(data) );
}

 

Will the axios example in the migration document work for what I am needing? Is axios part of Hubspot or will I need to reference it first?

Thanks,

Terry McMillan

0 Upvotes
1 Accepted solution
tmcmillan99
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Help converting API code to Private App code

SOLVE

@dennisedson I believe this post can be disregarded. I don't think the code referencing the API is needed anymore. It appears that the other developer had changed the code for date filtering and that is working without the deleted events table. My apologies for the wasted time.

 

Terry

View solution in original post

0 Upvotes
6 Replies 6
tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Help converting API code to Private App code

SOLVE

Would this be an appropriate conversion?

const fetchData = async () => {
  const { data } = await axios
    .get('https://api.hubapi.com/cms/v3/hubdb/tables/5307651/rows/',
    {
      headers: {
        Authorization: 'Bearer YOUR_ACCESS_TOKEN'
      }
    });
    .then(response => response.json())
    .then(data =>  listing_delete(data) );
}
0 Upvotes
tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Help converting API code to Private App code

SOLVE

@dennisedson  Do you know anyone that could help me out with my code conversion? I'm sure it would be an easy fix for someone with more javascript knowledge than me.

Thanks,

Terry

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Help converting API code to Private App code

SOLVE

Hey Terry,

I am a little afraid to ask, but is this something that is rendered on the front end 😬

You do not want to expose your api key or bearer token on the front end of your site (in this case, front end = viewable by looking at the source code) 

 

@Teun can guide you with the JS part of it ,but I would suggest giving us some more insight into this module so that we can determine if you are exposing secrets that you don't want to be exposing!

0 Upvotes
tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Help converting API code to Private App code

SOLVE

@dennisedson Unfortunately, you are correct with it being exposed on the front end. As a result, I have removed the code for now. 

 

I didn't develop it so I am trying to figure out what the code is needed for. It's in an event list module that pulls data from a HubDB table showing a list of webinars or training classes depending on what HubDB table is specified. It appears part of the javascript code is comparing the event list rows to another HubDB table for deleted events. If there is a match on the row id, it hides the event. The original code I included that was referencing the API key was accessing the deleted events HubDB table.

I will try to find out why it was needed.

 

If it is still needed, is there any documentation on how to reference the private app token without exposing it on the front end? Or do I even need a private app token? Could I do the comparison just using Hubl code?

0 Upvotes
tmcmillan99
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Help converting API code to Private App code

SOLVE

@dennisedson I believe this post can be disregarded. I don't think the code referencing the API is needed anymore. It appears that the other developer had changed the code for date filtering and that is working without the deleted events table. My apologies for the wasted time.

 

Terry

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Help converting API code to Private App code

SOLVE

No wasted time at all!    Always bring your questions here!  Only way we will all learn ❤️

0 Upvotes