Automatically enrich new user profiles with rich data from Clearbit.
Speaker 0: Clearbit provides an enrichment API that lets you send off just an email address for a person, and it will return a much more full contact containing all the information that Clearbit provides. In this episode of Quick Connect, we're going to automatically enrich data from new users in our director's project. So with that, let's get started. The first thing you'll need is a Clearbit API key, which you can get inside of the Clearbit dashboard. It's called the secret API key, so just go ahead and copy that.
And be certain that no one else ever gets hold of this key. Otherwise, they can also perform requests against your Clearbit account. I save this for later, and let's head back over to our Director's project to set up our connection. Here in our directors project, let's create a new flow. I'm gonna call this one clearbit enrichment.
For the trigger, we're going to use an event hook and make this action non blocking. That means that an item, a user will be entered into the database and the clear bit enrichment will happen in parallel, which means we don't slow down or otherwise prevent the user creation from taking place. The scope is going to be items dot create on the directors users collection. Hit save to set up our trigger. Before we continue, we are going to see what the shape of the data is when a new user is created.
So let's save this flow, head over to our user module, and create a new user. I'll just call this one joeblogs, very original, joe@example.com, and hit save. Let's go back over to our flow and we'll see here that there is a one inside of the logs. So this is one time that this flow has been triggered. We see here in the payload that we get a first name, a last name, and an email, and indeed any other information provided on creation of this user.
So take a note here that we have payload email. This is where the email lies, which we're going to need in a moment to use Clearbit. Also, take a note that this user, this item in the director's users collection has a unique key. We'll also need this later when we update the user record with the Clearbit data. The next thing we're gonna do is create an operation I'm gonna call this one clear bit and take note that the key is also Clearbit or lowercase.
This key will be important later. We're going to request a URL, and we're going to send a get request to the Clearbit API. So as per the Clearbit documentation, we're using the email people enrichment endpoint. So person.clearbit.comvone/people/email, and then a dynamic value based on the value of the trigger. So just before it was joe@example.com.
Now to authenticate with Clearbit, we're going to need to add a header. So we're gonna go ahead and do that. The header name is authorization, and the value is bearer space, and then your Clearbit API key. Once again, make sure other people don't see this key as they don't provide a way to invalidate and regenerate an API key manually. So let's go ahead and give this a test.
Let's hit save. Let's go back to our user module. Let's create a new user. I'm going to use our CEO Ben's email address here and hit save. Let's go back to our flows.
Let's look at our latest log here, and let's look at the returned payload from Clearbit. We see that it was a successful request. There's an there's a property called data, which is an object. And inside of this, a large object containing all the information that Clearbit holds on, Ben. So we have things like well, it's the Gravatar URL, so that's like the the avatar, LinkedIn usernames.
We don't have a Twitter handle, but that would be here. GitHub username, Facebook. We also have things like where are they based, what's their time zone offset, and stuff like that. The website direct to. Now what we're gonna do just to demonstrate how you would then go and update a user is we're just gonna take the location here, and we're going to update Ben's brand new user profile with the location.
If we take a look back at the user directory, a user object here, we see there's a bunch of provided fields, location, title, description, tags, and so on. You can add custom fields inside of the data model settings in your director's project. But seeing as location already exists, we'll just use that. So let's add one more operation here, and we're gonna make this an update data operation. I'm gonna go in here.
And first thing we're gonna do is say we're gonna update an item in the directors users collection. The ID of the user we're updating will be trigger dot key. Remember I mentioned that earlier on? And the payload, the data we will actually be updating is the location. And we said that this would be clear bit dot data dot location.
It's clear bit because that was the key on this step here that return the data. So let's hit save, save once more, and run this flow again. Just to keep this easy, I'm gonna delete this user and then recreate it so we don't get confused. Perfect. We'll hit save.
In the background the moment I hit save the user was saved but also the Clearbit operation was run Firstly, we see that it did indeed run here. If I look at that user item, we see the location has been updated. So you can, of course, update as many fields as you want, including your custom fields. Now there are a few notes I wanna make once as we get to the end of this little guide here. Firstly, Clearbit provides no guarantee around what data is going to be returned on an individual.
So what you may wanna do is add an additional step here between the request and the update data to check what exists and only add that into the payload. The reason that's important is if there is a value which is null or empty and it already exists in your director's project, it will be overwritten by the empty value. So you wanna add an extra step in there. Next, you have to be cognizant of the fact that every time you make a request to clear it, it's using up API quota or maybe costing money if you have paid agreements with them. So you may not wanna do this automatically on every user.
You may want to do this manually. Perhaps you add a button on a user profile that will trigger this, or you do it based on some other event, like they get in touch with the salesperson or there's a record created in another collection or so on. The final thing to note is today we use the enrichment API that Clearbit provides. They have an additional API called the combined enrichment API that will also return a bunch of information about a company. So that could be useful.
You know, you create a collection full of companies, and then you link users directly to their companies automatically using the ClearBit data. So I hope you enjoyed this episode of quick connect I'll see you next time