Integrating Thnks with HubSpot Using Python
This guide shows you how to automatically send Thnks gifts through HubSpot workflows using custom code actions with Python.Prerequisites
- HubSpot Operations Hub Professional or Enterprise license (required for custom code actions)
- Thnks API Key (Authorization Token)
- Thnks Gift ID for the gift you want to send
- Access to HubSpot Workflows
Python Code for HubSpot Custom Code Action
Use the following Python code in your HubSpot custom code action to send Thnks gifts:Setup Instructions
Create or Edit a HubSpot Workflow
- Log into HubSpot and navigate to Automation > Workflows
- Create a new workflow or edit an existing one
- Choose your enrollment trigger (e.g., after a meeting is logged, contact property change, etc.)
Add a Custom Code Action
- In the workflow editor, click the + button to add an action
- Select Custom code from the action options
- Choose Python 3.9 as the language
Configure Input Fields
Set up the following input fields in the custom code action:
email- Contact’s email addressfirstname- Contact’s first namelastname- Contact’s last namehubspot_owner_id- The HubSpot owner’s name or ID
Add the Python Code
- Copy the Python code provided above
- Paste it into the code editor
- Replace the placeholders:
- Replace
<GIFT ID>with your actual Thnks gift ID (e.g.,12345) - Replace
<API TOKEN>with your Thnks API authorization token
- Replace
Configure Output Fields
The code returns the following output fields that you can use in subsequent workflow actions:
email- The recipient’s email addressresponse_status- HTTP status code from the API callresponse_data- Full response from the Thnks APIerror- Error message if the request fails
Test the Workflow
- Save the custom code action
- Use the Test feature to run the workflow with a test contact
- Check the workflow execution logs to verify the gift was sent successfully
- Look for a 200 or 201 status code in the response
Customization Options
Dynamic Messages
You can customize the message using any HubSpot contact properties. For example:Different Gifts for Different Scenarios
You can use conditional logic to send different gifts:Multiple Recipients
To send to multiple recipients, expand the recipients array:Error Handling
The code includes error handling to catch and report issues:- Network errors
- Invalid API credentials
- Missing required fields
- API rate limits
error output field.
Best Practices
- Test thoroughly - Always test with a small group before rolling out to all contacts
- Secure your API key - Never share your Thnks API token
- Monitor usage - Keep track of gifts sent to manage your Thnks account balance
- Use delays - Consider adding delays between enrollment and gift sending for better timing
- Add conditions - Use workflow branches to send gifts only for qualified contacts
Troubleshooting
Common Issues
- 401 Unauthorized - Check your API token is correct and active
- 400 Bad Request - Verify all required fields are populated and gift ID is valid
- Network errors - Ensure HubSpot can reach the Thnks API endpoint
- Missing data - Confirm all input fields are mapped to existing contact properties
Debug Tips
- Use the
print()function to log values during testing - Check the workflow history for detailed execution logs
- Verify your gift ID is active in your Thnks account
- Test with your own email first before sending to contacts