Skip to content

zenaton-samples/hubspot-contacts-sync

Repository files navigation


Build and run event-driven processes within the product journey in days instead of months.
ie. payment, booking, personalized communication sequences, ETL processes and more.
Explore the docs »
Website · Sample projects · Examples · Tutorial

Table of contents

Hubspot Contact Sync

This Zenaton project shows how you can use the Hubspot integration to sync inbound contacts and reach out at the right moment if a user is struggling to complete their activation process.

The workflow launches when the user registers in the application and we create a contact in hubspot. The workflow waits for the first 'event' in the activation process and if the user completes it then it waits up to 20 minutes for the second event. If the user does not complete the second event, then we know there is a problem so they are marked as a 'user in trouble' so that someone can reach out to them (or other automations can be added like emails, etc)

How to run it

Requirements

To run this project, you need the following:

  • A Hubspot account.
  • A custom "Contact Property" named "Became a user in trouble date" of type "Date picker" set in your Hubspot settings.
  • A Zenaton account, to get your App ID and API Token.
  • The Zenaton Hubspot integration correctly setup. You can set it up on your Dashboard. Read the full documentation if you need help.

Zenaton Agent setup

Running the Agent on Heroku (Recommended)

Running the Agent on Heroku is the quickier way to get started. Make sure you have an account on Heroku before continuing.

Click the following button to deploy this project on Heroku. You will be prompted for your Zenaton credentials and your Hubspot integration ID. Make sure to fill-in them correctly and click "Deploy".

Deploy

If you go to the Agents page on your Dashboard, you should see one agent connected.

Running the Agent locally

Make sure you have NodeJS correctly installed on your system. If you don't, you can download NodeJS here.

Clone this repository:

git clone [email protected]:zenaton-samples/hubspot-contacts-sync.git

Go into the project directory and install dependencies:

npm install

Fill-in the .env file with all the required credentials. You can find your Zenaton App ID and API Token on this page. You will also need to fill your Hubspot integration ID which you can find on this page.

Install the Zenaton Agent on your system:

curl https://install.zenaton.com/ | sh

And then run the agent:

zenaton listen --boot=boot.js

If you go to the Agents page on your Dashboard, you should see one agent connected.

Running the Agent in Docker

Make sure you have Docker and docker-compose correctly installed on your system. If not, you can find the installation instructions for Docker here

Create your .env file by running the following command:

cp -n .env.sample .env

Fill-in the .env file with all the required credentials. You can find your Zenaton App ID and API Token on this page. You will also need to fill your Hubspot integration ID which you can find on this page.

Then, you can start the agent:

cd docker && docker-compose build && docker-compose up

If you go to the Agents page on your Dashboard, you should see one agent connected.

Other hosting options

You can check our documentation for more deployment options: AWS, Google Cloud, Clever Cloud, and more.

Running the workflow

You're all set. It's time to start the workflow. We will use the curl command in a terminal to do that, but you can start the workflow from your application, in any programming language as long as you have access to an HTTP client.

Make sure to replace <YOU API TOKEN> and <YOUR APP ID> with the one you retrieved on the Zenaton website before using the following command.

curl --request POST \
  --url https://gateway.zenaton.com/graphql \
  --header 'authorization: Bearer <YOUR API TOKEN>' \
  --header 'content-type: application/json' \
  --data '{"query":"mutation ($input: DispatchWorkflowInput!) {\n  dispatchWorkflow(input: $input) {\n    id\n  }\n}\n","variables":{"input":{"appId":"<YOUR APP ID>","environment":"dev","name":"HubspotContactSync","input":"[{\"email\": \"[email protected]\",\"firstname\": \"John\",\"lastname\": \"Doe\", \"phone\": \"+33623456789\"}]","tag":"user:123","version":null}}}'

This starts the workflow and you should be able to see it on your Dashboard.

The workflow will start by creating a new contact in Hubspot. Make sure your don't already have a contact with the same email address in Hubspot, otherwise the creation of the contact will fail.

After creating the contact, it waits for a start_process event which could be anything your user is beginning to do in your own application.

Send events to the workflow

Let's send this event using a curl command again. You can also send events from your application using an HTTP Client to send events through the Zenaton API.

Again, make sure to correctly replace the <YOUR API TOKEN> and <YOUR APP ID> placeholders in the following command, and then run it:

curl --request POST \
  --url https://gateway.zenaton.com/graphql \
  --header 'authorization: Bearer <YOUR API TOKEN>' \
  --header 'content-type: application/json' \
  --data '{"query":"mutation ($input: SendEventToWorkflowsInput!) {\n  sendEventToWorkflows(input: $input) {\n    status\n  }\n}\n","variables":{"input":{"appId":"<YOUR APP ID>","environment":"dev","name":"start_process","data":"[]","selector":{"name":"HubspotContactSync","tag":"user:123"}}}}'

Check your Dashboard to see the event that has been received by the workflow. And you will see the event start_process has been received by your workflow, and it is now waiting for a complete_process event for at most 20 minutes. If this event is not received within 20 minutes, it's probably that something went wrong.

Now you can send the complete_process event with the following curl command. Make sure to correctly replace the <YOUR API TOKEN> and <YOUR APP ID> placeholders before running the command:

curl --request POST \
  --url https://gateway.zenaton.com/graphql \
  --header 'authorization: Bearer <YOUR API TOKEN>' \
  --header 'content-type: application/json' \
  --data '{"query":"mutation ($input: SendEventToWorkflowsInput!) {\n  sendEventToWorkflows(input: $input) {\n    status\n  }\n}\n","variables":{"input":{"appId":"<YOUR APP ID>","environment":"dev","name":"complete_process","data":"[]","selector":{"name":"HubspotContactSync","tag":"user:123"}}}}'

After running the command, you will see the complete_process received by your workflow. It means the user successfully completed the process in the given timeframe.

Now, try to restart the workflow with a different email address, and at the last step, instead of sending the complete_process event, wait 20 minutes. You will see your workflow will do an extra step: it will update the Hubspot contact to set the "User became in trouble date" property to the current date. This way you will be able to easily find in Hubspot contacts who have been in trouble with your application and you can decide what to do next to help them.

Going further

There are a few things that could be improved in this workflow:

The workflow starts by creating a contact, but sometimes this contact will already exist because it has been added from somewhere else. In that case, try to improve the workflow by first checking if the contact exists in Hubspot, and if it does, updating it instead of creating it.

Troubleshooting

Questions

If you encounter any issues or problems click on the chat in the bottom right hand side of the screen on the Zenaton dashboard.

Issues with the Zenaton Agent

If you have a question about the Agent installation or usage, you can take a look at the dedicated documentation.

Issues with this project

If you have any issue with this sample project, feel free to open a new issue on the repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published