hey everyone my name is brian morris and thanks for stopping by my channel today we're going to look into how you can create an integration with notion and then query some data from a database using the notion api so let's hop right to it okay so you can see here i have the landing page for the notion developers uh portal uh pulled up the url you wanna go to is developers.notion.com um before you get started with this tutorial make sure you actually have a notion account you're signed in with it because you're gonna need it to follow along so in the upper hand corner you can see there's a button here that says my integrations this is the first step we need to do we need to create an integration and register it on notion side so let's go ahead and click on that and then if you've never done this before you won't have any integrations listed here but we're going to go ahead and click on new integration and let's just name this my first integration you can see there is the option to upload a logo we're not going to do that today it's pretty it just makes it look pretty we need to associate it with a workspace though so i'm going to select streaming too because that's usually the workspace that i've been using lately to play around with things and then there's different uh security capabilities you can add in here so we want our integration to be able to read content update content and insert context we're going to access those in a later video and then i'm also going to leave the default of read user information including the email address so let's go ahead and click submit and that's pretty much it you've created your first integration but we need to grab this internal integration token and this is what we can use to start testing our integration uh the our current integration is not going to be available to everyone who uses notion it's just for us and anyone who has this specific
token uh so let's go ahead and click show and copy this and you want to keep this a secret you never want to leave this public i'm obviously going to delete it once we're done with the video but we're going to go ahead and paste that off to the side here so i can reference it later okay alrighty so now that we have this created let's go into notion and actually create a database so inside of notion i have pulled up here it's just a blank page nothing's been done here so far so if i delete this out it gets me a couple of options here i'm just going to click on this database item here which is going to create it's going to turn the page into a database table version specifically and let's just say like my first database and let's create a couple of records in the database we'll say uh record one and let's say my first page and hello world why not right hello world is common anytime you're doing anything with developments let's go ahead and throw hello world there uh and this is pretty much all we need to add to the records now in order before we can actually access the data uh through the notion api we need to share the page or database we want to access with our api specifically so we're going to go ahead and click on share up here and instead of typing anything here we can click invite and then you're going to see your integrations that have access to this specific workspace listed in this dialog here so let's go ahead and click on my first integration and then click invite again and that's pretty much it we are done here so let's hop over to vs code and start writing uh writing some code to access it okay so we're in vs code now you can see i have a fairly empty project built up with one file called tests.http now we're just going to use this to be able to send requests to the notion api it's using a plugin for vs code called the vs code rest client plugin i actually made a
video about that a while ago on how you can use this uh check the one of the corners for a link to that but uh it's good stuff uh so we can do here is we can actually start typing um some very basic http commands that's going to let us execute a request to the notion api so the first thing i want to do is i want to query some information about the database itself so let's type in git and then we'll type in https colon slash api.notion.com see it's already pre-populating some stuff for me dot com slash v1 slash databases v1 slash databases and then i'm going to put a slash here we're going to stop here for a sec let's go into a new line and just get the rest of our arrest of this all settled and we'll type in authorization which is uh the header we're going to type our token in bearer is what you want to start that off with and now i'm going to copy in the secret that we or the token that we had pulled from the previous step and paste that afterwards you want to make sure there's a space between bear and that token and the last required header is actually notion hyphen version uh which is how they version their api using the headers so the current version at the time of this recording is two zero two one uh slash zero eight slash one six uh likely is when that api version was released and now we need to get the id of the database before we can actually execute this request so i'm actually going to hop back over to notion and a little trick you can use to get the id of a database if you have it open in a web browser you can just look at the url but if not you can uh select these little three dots here and copy a link to the view and then we're going to add a couple lines in vs code and paste this in now you'll see this uh this this is our url let's actually clear this out so we got some more room to work here uh you can see here's the url for notion and then we have this random gibberish uh string of
characters and numbers this is actually the database id now you want to be careful not to grab the one that's after the v because that's the view id so it's not the same thing so i'm going to copy this and paste this into the url up here and we can get rid of this we don't really need it anymore let's save the file and i'm going to go ahead and click send request and you can see we get a 200 okay which is which is good exactly what we're looking for if i scroll down a little bit you can see there is the the object type of database uh here's the title it's my first database just as we specified and there's a bunch of other attributes here that you can you can look through like the different properties that are available to the specific database uh but mind you this doesn't actually include any of the records for the database there's actually a different http call you have to you have to use for that so i'm going to add three hash marks here just to give myself a new request here and we're going to copy and paste this below because most of it is actually the same so the end point you want to hit is we want to leave the url can stay the same we want to put forward slash query at the end of it which is what you can use to query databases uh and we have to change the request type from a git to a post because uh you can spat you can optionally pass in filters to filter out the data that you're requesting back but it's not necessary for this tutorial we can leave it just as is we'll click send request again we got another 200 and let's widen this up a little bit let's scroll down and we can see here our results come back as an array let's minimize all these objects here so here's three objects that came back inside of our results a results object and this is an object type of page if we scroll down we can look here's our properties same same things that we saw in the in the metadat
a about the database but this is the page itself uh we can see type title is really the one we're interested in here because this is where we put all of our our different uh our different content the the records the items that we put into the database so you can see we have hello world here looking at the next one you can see we have my first page and last one would probably be record one if i remember properly uh yep record one um so there you have it there you go there's exactly how you would get started writing some kind of integration with uh with notion uh so just to recap we created an integration uh and then we went over to vs code using the rest client plug-in uh wrote a couple of tests to get some data did get some information from a database and um yeah you're off running so if you like this kind of content uh please do me a favor like share the video and subscribe to the channel if you wouldn't want to get in touch with me directly the best way to do so is on twitter my handle is at bryan mmdev and i will see in the next one bye-bye Note Type: Crawled Text Associated URL: https://www.youtube.com/watch?v=Hk7Vk_v4yfo Model ID Name: null Linked Note IDs: User Name: Umair Kamil User Email: newsletter@umairkamil.com User Profile Picture: https://dl.airtable.com/.profilePics/943d1d1216fda768bca1e9b75e277ab1/e6167817 Custom Field 1: null Custom Field 2: null Custom Field 3: null Custom Field 4: null Custom Field 5: null