HubSpot is a lightweight yet powerful Customer Resource Management platform. A common action in a solar business workflow is creating a Project in Aurora and a link directly from a CRM to the newly created Project. This guide provides requirements, key terms, steps, and additional considerations for setting up a custom button in your HubSpot instance.
Table of Contents:
- Required Features
- Key Terms
- Creating a Sandbox environment
- HubSpot Fields
- Creating a Workflow
- Setting up a trigger
- Configuring the Action
- Adding Properties
- Inserting Code
- Set Project URL link
- Testing the Workflow
- Deployment to Production
Required Features
HubSpot Workflows: This feature allows users to automate business processes. Available with any of the following subscriptions:
- Marketing Hub (Professional or Enterprise)
- Sales Hub (Professional or Enterprise)
- Service Hub (Professional or Enterprise)
- Operations Hub (Professional or Enterprise)
Sandbox: Access to a sandbox environment to build and test the API integrations before deploying them to Production. It is also available with any of the subscriptions above.
Key Terms
Module: A type of object in HubSpot — just like a Project, Design, or Agreement object in Aurora.
Creating a Sandbox environment
It is highly recommended to perform the first-time setup in a Sandbox environment before deploying to a Production environment.
To create a Sandbox environment:
- Navigate to Settings > Account Management > Sandboxes
- Click on the orange Create Sandbox button in the top right
- Input a Name and choose which production assets you need to copy over.
- Click Create at the bottom of the form, and HubSpot will begin creating the sandbox in the background.
- Once complete, navigate to your user icon in the top right, hover over the current Account you're in, and click on the sandbox (if it appears there) or click on All Accounts to search for and find your newly created sandbox environment.
For additional context, please refer to HubSpot Academy's courses, which can be found here.
HubSpot Fields
Fields that are already in HubSpot:
- Deal ID
- Address (Headquarter / Address)
- Deal Name
Note: You may also have, or choose to create, these optional but recommend fields, which will simply remain blank if not included:
- Email (Single-line text)
- Phone (Phone number)
- First Name (Single-line text)
- Last Name (Single-line text)
The only required custom field when creating a link directly to the Aurora Project once created is a URL field for the "Aurora Project URL".
- Mouse over to the left sidebar and click on CRM, then the desired module (i.e. Deals)
- In the top right of the page, click on Actions, then Edit Properties
- Click on the orange button Create property on the right side
- Enter values as desired for the Details tab.
- For example, based on the screenshot above:
-
Property label: Aurora Project URL
- Can be anything you choose, but will be needed when referencing later.
-
Object type: Deal
- Can be any Module as you choose, but is typically for closed Deals or Contacts (formerly 'Leads').
-
Group: Deal information
- Can be any group of fields, depending on your setup
-
Description: Direct link to corresponding Project in Aurora's web app
- Can be any description that explains it to anyone using the field.
-
Property label: Aurora Project URL
- For example, based on the screenshot above:
- Click on Field type on the left side
- Select Rich text from the dropdown menu
- [Optional] Click on the Preview tab to double check how the field appears
- Click Create in the top right
- [optional] Description: Provide an explanation for those re-using the function later.
Creating a Workflow
- On the left side in the grey panel, click on Automations, then Workflows
- On the right side, click on Create Workflow, then choose From scratch
- Click on Deal-based and click Next
Setting up a trigger
In this tutorial, we’ll use the event of “When a Deal is marked as Closed Won”. The trigger that works best for your case depends on your workflow.
- In the middle of the page, click on the orange Set up triggers button
- Choose an “Enrollment trigger”, such as When an event occurs.
- In the “Add criteria” panel that opens to the right, under “CRM” select Property value changed
- Click in the “Property name” search bar, type in “Is Closed Won” to find and select the status.
- Finally, click on the True option under “is equal to”
- Click Save
Configuring the Action
- Click on the grey + button under the trigger to start configuring your action
- On the left side, under “Choose an action”, scroll down and click on Data Ops, then Custom Code
- Under “Language”, select Python 3.9
- [Optional] Add a Description that will be visible on the workflow diagram
- Under “Secrets”, use the dropdown to select Add secret
- In Secret name, enter a name for your API Key. In the example, we’ll use “aurora_api_sandbox”.
Under Secret value, this is where you’ll paste your Aurora tenant’s Bearer token, found here.
- Click Save
Adding Properties
- Under “Properties to include in code”, click in the “Key” text box to enter the name of the property to be used in the code.
- Click on Add property to add each additional property.
- Enter these recommended variables that map to an Aurora Project:
Key HubSpot property address Headquarter / Address email Email f_name First Name l_name Last Name
- Click Save in the bottom-right of the pop-up.
Inserting Code
Copy the below code and paste it into the code editor space.
import requests
import json
import os
def main(event):
tenant_id = "tenant_id"
url = f"https://api-sandbox.aurorasolar.com/tenants/{tenant_id}/projects"
address = event.get('inputFields', {}).get('address', "")
customer_first_name = event.get('inputFields', {}).get('f_name', "")
customer_last_name = event.get('inputFields', {}).get('l_name', "")
customer_email = event.get('inputFields', {}).get('email', "")
customer_phone = event.get('inputFields', {}).get('phone', "")
deal_name = event.get('inputFields', {}).get('name', "")
payload = json.dumps({
"project": {
"location": { "property_address": address },
"external_provider_id": f"{event.get('object').get('objectId')}",
"name": deal_name,
"customer_first_name": customer_first_name,
"customer_last_name": customer_last_name,
"mailing_address": address,
"customer_email": customer_email
}
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f"Bearer {os.getenv('bearer_token')}"
}
response = requests.post(url, headers=headers, data=payload)
response_data = response.json()
project_id = response_data['project']['id']
project_url = f"https://v2-sandbox.aurorasolar.com/projects/{project_id}/overview/dashboard"
return {
"outputFields": {
"project_url": project_url
}
}
- Replace
tenant_id
with your sandbox Tenant ID. This can be found at https://v2-sandbox.aurorasolar.com/settings/api/tokens - Ensure the
bearer_token
variable (line 32) is named the same as the secret Secret created earlier. - Click on Add output to add the
project_url
as an output variable to be used later in the workflow - Enter the Data type as String and the variable name as "project_url"
- Click Save
Set Project URL link
For the last step of this workflow, we’ll set the property of Project URL based on the project_url
field created in the previous Custom code step.
- Click on the + icon under the Custom code step:
- Use the “Target object” dropdown to select Deal (Current object)
- Under “Property to set”, search for and select Project URL field.
- Click inside the Project URL text box on the left side
- Click on Enrolled Deal, scroll down to Action properties and select Action outputs
- On the next screen, select the project_url variable under Custom code
- Click Save.
Testing the Workflow
- Add a name for your new workflow by clicking on the name in the top center
- [Optional] Add a description, or click Generate for AI to create one for you.
- Click on Test in the top right.
- Click on Choose a deal and search for Choose the record to use as the preview.
- Click Test
- You'll be greeted by a test result like the one below.
- Click Review and publish in the top right
- Click through the Steps to review the Workflow details and choose any permissions as needed
Deployment to Production
- Navigate to your HubSpot Production account and perform the same steps as above (from HubSpot Fields until Adding Properties).
- When doing Configuring the Action in Production, follow the same instructions by adding a new key from your Aurora production tenant, which can be found in Settings > API > API tokens.
- Continue through the Inserting Code section. In this step, be sure to:
- Replace
api-sandbox
withapi
- Replace the sandbox
tenant_id
with your productiontenant_id
- Replace the sandbox
bearer_token
with your productionbearer_token
- Replace “
v2-sandbox
” in the project_url with “v2
”
- Replace
- Finally, ensure that your API Version is consistent between sandbox and production
- Click Save.
- Follow the rest of the steps in Inserting Code through Testing the Workflow in your Production environment