Update jobtitle country industry from linkedin
Tags: #hubspot #crm #sales #contact #naas_drivers #linkedin #identity #scheduler #naas
Author: Florent Ravenel

Input

Import library

1
from naas_drivers import hubspot, linkedin
2
import naas
3
import pandas as pd
Copied!

Setup your HubSpot

👉 Access your HubSpot API key
1
HS_API_KEY = 'YOUR_HUBSPOT_API_KEY'
Copied!

Setup your LinkedIn

👉 Get your cookies
1
LI_AT = 'YOUR_COOKIE_LI_AT' # EXAMPLE AQFAzQN_PLPR4wAAAXc-FCKmgiMit5FLdY1af3-2
2
JSESSIONID = 'YOUR_COOKIE_JSESSIONID' # EXAMPLE ajax:8379907400220387585
Copied!

Schedule your notebook everyday

1
#-> Uncomment the 2 lines below (by removing the hashtag) to schedule your job everyday at 8:00 AM (NB: you can choose the time of your scheduling bot)
2
# import naas
3
# naas.scheduler.add(cron="0 8 * * *")
4
5
#-> Uncomment the line below (by removing the hashtag) to remove your scheduler
6
# naas.scheduler.delete()
Copied!

Model

Get all contacts in Hubspot

1
properties_list = [
2
"hs_object_id",
3
"firstname",
4
"lastname",
5
"linkedinbio",
6
"jobtitle",
7
"country",
8
"industry",
9
]
10
hubspot_contacts = hubspot.connect(HS_API_KEY).contacts.get_all(properties_list)
11
hubspot_contacts
Copied!

Filter to get "jobtitle", "country", "industry" = "Not Defined" and "linkedinbio" = defined

1
df_to_update = hubspot_contacts.copy()
2
3
# Cleaning
4
df_to_update = df_to_update.fillna("Not Defined")
5
6
# Filter on "Not defined"
7
df_to_update = df_to_update[(df_to_update.linkedinbio != "Not Defined") &
8
(df_to_update.jobtitle == "Not Defined") &
9
(df_to_update.country == "Not Defined") &
10
(df_to_update.industry == "Not Defined")]
11
12
# Limit to last 50 contacts
13
df_to_update = df_to_update.sort_values(by="createdate", ascending=False)[:50].reset_index(drop=True)
14
15
df_to_update
Copied!

Get identity from Linkedin

1
for _, row in df_to_update.iterrows():
2
linkedinbio = row.linkedinbio
3
4
# Get followers
5
df = linkedin.connect(LI_AT, JSESSIONID).profile.get_identity(linkedinbio)
6
jobtitle = df.loc[0, "OCCUPATION"]
7
industry = df.loc[0, "INDUSTRY_NAME"]
8
country = df.loc[0, "COUNTRY"]
9
10
# Get linkedinbio
11
df_to_update.loc[_, "jobtitle"] = jobtitle
12
df_to_update.loc[_, "industry"] = industry
13
df_to_update.loc[_, "country"] = country
14
15
df_to_update
Copied!

Output

Update jobtitle, country, industry in Hubspot

1
for _, row in df_to_update.iterrows():
2
# Init data
3
data = {}
4
5
# Get data
6
hs_object_id = row.hs_object_id
7
jobtitle = row.jobtitle
8
industry = row.industry
9
country = row.country
10
11
# Update
12
if jobtitle != None:
13
data = {"properties":
14
{"jobtitle": jobtitle,
15
"industry": industry,
16
"country": country}
17
}
18
hubspot.connect(HS_API_KEY).contacts.patch(hs_object_id, data)
Copied!
Copy link
Edit on GitHub