Step 7 - Run and verify
Time to test our integration! Let's run the script and create a company in HubSpot.
Make the script executable
First, make your script executable:
Set your API key
You'll need your Lightyear API key. You can find this in your account settings in the Lightyear dashboard.
Set it as an environment variable:
Tip: You can also create a
.env
file to store your API key, but make sure to add it to.gitignore
!
Run the script
Now run the script:
You should see output like this:
Verify in HubSpot
Let's confirm the company was created:
- Log into your HubSpot account
- Navigate to Contacts → Companies
- You should see your newly created company!
The company will have:
- The name you entered
- An auto-generated domain based on the company name
- A creation timestamp
- Default HubSpot properties
Troubleshooting
If you encounter errors:
"Please set LIGHTYEAR_API_KEY environment variable"
- Make sure you've exported your API key
- Check that the key is valid
"Request failed: 401 - Unauthorized"
- Your Lightyear API key might be incorrect
- The managed user might not exist
"Request failed: 404 - Not Found"
- The managed user ID might be wrong
- The integration might not be added to the user
"Error creating company"
- The HubSpot access token might be invalid
- You might not have authorized the integration yet
- Check HubSpot API limits
Success!
Congratulations! You've successfully:
- Created a managed user in Lightyear
- Connected a HubSpot integration
- Built a script that uses Lightyear's API
- Created data in HubSpot through your integration
What's next?
Let's explore how to make this production-ready and what else you can build.