HubSpot.Extend() Workshop 2022 | Creating a Private App and Custom Object

A developer walks through setting up a HubSpot private app, configuring scopes, and creating a custom object using the HubSpot CLI. Learn the command line steps and security setup needed to integrate with HubSpot's platform.
Now we're going to take some additional steps to just get our, our app set up. So we are going to configure our HubSpot account. We'll create a private app, and we'll create a custom object and then we'll also fork and clone or download the GitHub repository that we're going to use to build the app in the third section. All right, so let's get into it. So, yep, this is just what I outlined. We'll create a private app, download the GitHub repo, and create a custom object using the CLI. All right, so let's talk a little bit about private apps and how to create a private app. So private apps are good if you're integrating with a single HubSpot account. If you wanted to use an app in multiple HubSpot accounts, you would create a public app. But we're going to create a private app so they use HubSpot configured access tokens instead of API keys. Private apps are more secure than API keys. And we'll cover that on the next slide. And you can scope permissions for each private app you create. So we'll talk more about that on the next slide as well. And you can create up to 20 private apps in your HubSpot account, with the idea being that you can scope your private apps as you can curate, make them as scoped as you want to be, and then have different apps for different jobs. So different apps might have access to different bits of data in, in your account. So API keys, they provide full read and write access to a HubSpot account. It's like having a super admin password to account to an account. So you actually can't create API keys anymore within HubSpot. Pretty soon you can't authenticate using API keys either. That's coming in November, but I don't remember the exact date. And then private apps, you can create multiple of these in your account. You can scope your permissions and you can also, which is a nice feature when you create permissions for your private app, you can later change the scopes. So that's nice. It's not fixed once you create it. So that's API keys and private apps. Private apps being a more secure way to authenticate with a single HubSpot account. So let's talk a little bit more about scopes. So there are different kinds of scopes you can grant your app. It's very similar to OAuth. So you can, you can say like this app can read and write contacts. It can read and write companies. Our app, the one that we're going to create, is going to have scopes for reading and writing custom objects and reading and writing custom object schemas. Because in our app we'll be creating a custom object, so it'll be useful to have those scopes. And then we're also going to add a CRM import scope to our app to allow us to import data into the CRM via the API. Let me just get something up real quick. Sorry about that. Yeah, so at the bottom of this slide, this is actually taken from the ui, which we'll look at in a second. These are the scopes for this app that we're going to create because we're going to be. Well, I'll. I'll hold on that. So what we're going to do now is we're actually going to create our private app and then after that we'll. We'll fork and clone or download the GitHub repo. So if you're following along at home, you'll need to. We'll now go into our. The developer test account that we created in the first step, and we're going to create our private app. So to do that in your HubSpot account here, you click on the settings icon, which is a really useful icon. It's where you get to many things, you know, I've said so many times, click on the Gear settings icon that I. It's just, it's burning in my brain now. And now we'll click on the Integrations tab in the left sidebar and right under there is private apps. So let's create a private app. By clicking on Create a Private App, you want to give your app a recognizable name so that when you see it in different places in the ui, you'll recognize immediately sort of which app it is. You also have the option to provide a description for your app that can be useful or. And a logo as well. So we gave our app a name. Let's click on Scopes to grant it the scopes we want it to have. So like I said before, we're going to use custom object scopes, so you can actually search. All right, so type custom and CRM objects. Custom and CRM schemas. Custom are. These are all this. These are scopes that we want. So reading and writing custom object data and then reading and writing custom object schemas, which are the. Basically the definition of the custom object. And also in the UI here on the right side, it tells you more about what Scope what tells you more about the scopes that you're selecting. So the other scope I said we'll need is the CRM import, so I will add that one as well. So you should now have five scopes, CRM objects, Custom read, Write, CRM Schemas, Custom Read and crmschemas Custom write and CRM Import. So five scopes together. I'll go ahead and click on Create app here. You'll get a warning that don't share this token with or only share it with people you trust. So it's just a best practice to always lock down this information. Don't include it in version control, don't include it in client side code. Even though the app is scoped, you're still, it still gives grants access to parts of a HubSpot accounts data. So I'll create that app, I'll close this for now and then it should open right up the private app that you just created. So this token here, you're gonna, we're gonna need this a bit later, so just keep this handy. This is the token we're going to use to authenticate later when we build the app itself. So that's creating the private app. So from here we created our private app. That's step one. We're going to also now download the GitHub repository. So this, the link for this, we will include this in the chat. But you can basically fork and then clone or download this. So if you have, if you don't have a GitHub account, you can create one, but you don't really, you don't necessarily have to fork this. But I will fork it. I'll just leave all the defaults. It's, it's going to end up in my account again. You don't have to fork it if you don't have an account. But forking it allows you to make your own commits and do your own work on it and sync it with your account. Okay, so I'm now going to add this into the directory that Nicole created in the first step. So you can clone it on the command line if you're authenticated with GitHub. Well, actually this is public, so but you can use the command line or you can just download it if you want to clone it. You know how to do that? You can do that. I'll just download the zip. Just so just because this is a step that I know everybody can follow. So I'll download the zip that's now in my downloads folder and I'm going to go Ahead and unzip the this guy. And I'll copy this directory, the unzip directory, and I'll paste it in my HubSpot Extend directory. So I have the, the uncompressed directory that I downloaded from GitHub and I added it into the HubSpot Extend directory that we created in the first step. So I'm in VS code now, and the directory is in there because I pasted it in my finder. So however, you can get the directory in the same directory as your YAML file, that's what you're going to want to do because we're going to use the CLI next to create a custom object. So the directory you have needs to be in the same directory as your YAML file, which is the same directory that's authenticated already with HubSpot from the first step. Okay, so we created the private app, we downloaded the repository, and the last thing we'll do in this section is create a custom object. If your YAML file's somewhere else, you'll want to add this directory wherever your YAML file is and or re authenticate with HubSpot in whatever directory you want to use. All right, so that's private apps, that's GitHub directory. Okay, so the last step we'll, we'll do here, which will really set us up to moving into creating the app, is we'll create a custom object. So what is a custom object? Well, in HubSpot we have standard objects which come out of the box. Contacts, companies, deals, and tickets. So in the main HubSpot navigation, you, there's the contacts menu item under which it has companies. And so these are all represented within HubSpot by default. But sometimes your business might need some other bit of data represented in HubSpot. And for that you can use custom objects. So you can represent whatever you need and it's specific to your company, your business, your to your use case. You can create a custom Object using the UI, using the APIs, or using the CLI. So there's three ways you can do it. Today we're going to demonstrate it. Creating a custom object using the cli. And this is because we're going to create an app that displays equipment rentals in a calendar view in the final section. So we're going to be creating an equipment rentals custom object. Yep. So we're going to do this on the command line. These are the commands we're going to use HS custom object schema, create, and then the path to the JSON SCHEMA and then you can also just view commands related to custom object schemas using the command HS Custom Object Schema. So let's go back to VS code. All right, here we are. So I'll open up this directory that I downloaded, Zoom, maybe one more level. So let me real quick run that command HS Custom Object Schema. So when I run that command, it tells me all the commands that are related to this, to custom object schemas, things you can do on the command line to interact with custom object schemas. So I can for example, run the command so HS Custom Object Schema list. So you can see I don't have any custom objects in this account. It tells me that this just returns an empty table. So let's, we're going to create our custom objects and the one we're going to create, like I said, is this AV Equipment Rentals object. So whenever you create a custom object, you have to provide a definition for the object which has different requirements. So we've already put together the definition for you essentially, which is contained in this JSON file. So we can see this equipment rentals object has a start date, an end date, an end date. It has a name, it has the, the name of the, the thing that's going to be rental rented, which in this case is a select dropdown. So this is the, and it's also associated with the contact object. The idea being that a contact of yours could be associated with a rental. So somebody rents an object or rents a piece of equipment. So that's the definition. So in order to create the custom object in the account, let me once again, HS Custom Object Schema Create is what we'll use. So HS Custom Object Schema Create and we'll just pass, actually let me CD into the, the directory first. So I was in the top level directory, but I just switched into the, the repo itself. So HS Custom Object Create. Okay, so success. You have no idea how stressful it is. Like when I enter this command, is it going to work? You're just waiting, waiting for the computer to tell you that you're wrong. Okay, but no, in this case it was a success. Great success. So what we can do is it's, it's now actually telling me I can command, click on this to view it in the account. I'll go back to the HubSpot account that we were using. And actually you can view custom objects under the Contacts menu. If you click on Contacts, you should now see AV Equipment Rentals under the Contacts. So your custom objects will appear under your contacts. If you have one, it'll show up, I believe. And if you have more than one, there will be another submenu that lists them all. So you can click on this. Let's go. And you can sort of do the same things you do with regular objects. You can create new instances and that sort of thing. Yeah. So that is creating a custom object using the cli.










