This documentation walks through how to set up a HubSpot workflow which can call the 6sense People Enrichment API. This allows you to enrich any HubSpot contacts based on data 6sense API returns. You can also use these values to trigger other actions in Workflows like enrolling in sequence, adding to list, creating a task, etc.
All 6sense APIs can be used in Hubspot workflows
Using HubSpot forms and interested in increasing form conversion rates by auto-filling your website forms? Check out Smart Form Fills!
Prerequisites:
6sense Enrichment API credits
Hubspot Workflows with action ‘Custom Code’. We are using Python to call the 6sense API so it is recommended to consult a developer. However we’ll give you the code to just copy and paste!
E-mail address in Hubspot.
Create a Workflow
Login to Hubspot. Navigate to Workflows > Create New Workflow.
Select Contact-Based Workflow > Blank Workflow.
Next, we want to set up Triggers for when you want the 6sense API to enrich the HubSpot contact record. This is a business decision that will need to be made by your team. You could enrich contacts if certain properties were missing. In this example we will trigger workflow when a new form has been submitted.
Select Set Up Trigger> When an event occurs > Has completed: Form submission.
We only want this workflow triggering once, so set ‘Should contacts be re-enrolled in this workflow?’ to No and Save.
Click + > Custom Code.
Language: Python 3.9
Secrets: You can store your 6sense API key in a Secret key and use it in your Python code. In the script below, we have our API key in Python script.
Property to include in code: We need to use the value from Email value from hubspot and set to ‘email’.
Copy and Paste the Python script below into Hubspot Code.
import requests def main(event): url = "https://api.6sense.com/v1/enrichment/people" email = event["inputFields"]["email"] # Define the payload payload = { "email": email } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Cache-Control': 'no-cache', 'Authorization': 'Token b3661xxxxxxxxxxxxxx' } response = requests.post(url, headers=headers, data=payload) # Check the response status code if response.status_code == 204: return { "outputFields": { "email": email, "status_code": 204 } } elif response.status_code == 200: # Parse the response JSON data response_data = response.json() # MAP all the fields from the response to output fields person_data = response_data.get('person', {}) company_data = response_data.get('company', {}) return { "outputFields": { "email": person_data.get("email"), "emailConfidence": person_data.get("emailConfidence"), "fullName": person_data.get("fullName"), "firstName": person_data.get("firstName"), "lastName": person_data.get("lastName"), "title": person_data.get("title"), "function": person_data.get("function"), "level": person_data.get("level"), "division": person_data.get("division"), "education": person_data.get("education"), "skills": person_data.get("skills"), "city": person_data.get("city"), "state": person_data.get("state"), "country": person_data.get("country"), "postalCode": person_data.get("postalCode"), "linkedinUrl": person_data.get("linkedinUrl"), "twitterUrl": person_data.get("twitterUrl"), "facebookUrl": person_data.get("facebookUrl"), "companyDomain": company_data.get("domain"), "companyName": company_data.get("name"), "companyRegion": company_data.get("region"), "companyCountry": company_data.get("country"), "companyState": company_data.get("state"), } } else: print("API request failed with status code:", response.status_code) return { "outputFields": { "email": email, "status_code": response.status_code # Include the status code in the output } }
This script is going to first check to see if our API found a match based on the e-mail address. If there is no match, it will output ‘status_code’: 204. If there is a match, it will return all data our API outputs. Full list of data available list here.
Data Outputs: Next we need to define the type and name of the data the 6sense API outputs that you want to use in other workflow action. These data outputs can then be used in any other actions within the workflow, like updating properties of the contact. It will be up to your team to determine which field you’ll want to use! Full list of data available list here.
Give it a test! Choose a contact and see what the API returns.
Now we need to determine what we want to do with the data that the API returns. To enrich Lead/Contact record properties, click the + to add a new workflow action.
Under Property Management > Set property value.
Set Target object to Contact or Lead.
Select which HubSpot property you want to enrich with 6sense data.
Search for the Data Output value (defined in step 7) you want to use to enrich. It will be listed under Action Outputs > Custom Code.
Repeat for all values you want to update HubSpot with!