HubSpot integration with Ory Actions
HubSpot is a CRM platform that can be used to manage data from marketing, sales, content management, and customer service. The HubSpot API in combination with Ory Actions makes it possible to integrate any of the Ory self-service flows with HubSpot. A common use case is to integrate via the HubSpot Contacts API with the Ory registration flow, so that new contacts are automatically created in the HubSpot contacts list whenever a new user signs up to our service.
The advantage of integrating Ory with HubSpot is that users signing up automatically become available to the CRM platform, facilitating lead generation and marketing campaigns (provided that users give the appropriate consents).
How Ory integrates with HubSpot
The following diagram illustrates how Ory integrates with HubSpot. In this example, we consider the case where the registration flow in Ory triggers an API call to HubSpot, automatically creating a new contact in HubSpot. In other words, a new record is created simultaneously in the Ory Identities database and in the HubSpot contacts list.
In this example, the API call to HubSpot is triggered as follows:
- The end user signs up to a new account using Ory Identities, completing the registration self-service flow.
- Upon completion, the registration flow triggers any actions registered under the
flows.registration.after.hooks
section of Ory Identities configuration. - The hook for the HubSpot CRM platform, registered under
flows.registration.after.hooks
, is now triggered, and Ory evaluates the Jsonnet template to construct the body of the API call. - The Ory action invokes the
/com/v3/objects/contacts
HubSpot API endpoint to create a new contact in HubSpot.
Create a HubSpot webhook
To set up the integration follow these steps
- Set up the necessary contact lists for your customer data. Creates a new private app for this integration in the Hubspot settings. For details of how to create a private app in HubSpot, see the Private apps page in the HubSpot documentation.
- Copies the access token from the new private app.
- Using the access key from the previous step, create and register an Ory Action for triggering a HubSpot API call whenever a user completes the registration flow.
- Test the integration to ensure that data is routed correctly from your application to HubSpot.
Configuration
Follow these steps to configure an integration that adds every newly registered user to your HubSpot contacts:
Not sure what Jsonnet is? Read the Ory Actions webhook guide.
-
Create a Jsonnet file. It transforms the identity data from Ory to a format HubSpot understands.
./hubspot_identify.jsonnetfunction(ctx) {
properties: {
email: ctx.identity.traits.email,
firstname: ctx.identity.traits.name, # User's first name taken from the "name" identity trait.
# ... # You can get more user data depending on the identity schema you're using.
},
} -
To use this Jsonnet snippet, encode it to Base64 and save it to the clipboard:
cat hubspot_identify.jsonnet | base64 | pbcopy
-
Define the Ory Action as a JSON object. Remember to replace the placeholders with your data.
./webhook-action.json{
"hook": "web_hook",
"config": {
"response": {
"ignore": true
},
"auth": {
"type": "api_key",
"config": {
"name": "Authorization",
"value": "Bearer {PRIVATE_APP_ACCESS_TOKEN}",
"in": "header"
}
},
"url": "https://api.hubapi.com/crm/v3/objects/contacts",
"method": "POST",
"body": "base64://{BASE64_ENCODED_JSONNET}"
}
} -
Add this action to your Ory Network project using the Ory CLI.
-
Use this command to trigger this action after all successful registrations:
ory patch identity-config {project-id} \
--add "/selfservice/flows/registration/after/hooks/0=$(cat webhook-action.json)" \
--format yaml -
Alternatively, use this command to trigger the action only for registrations with social sign-in profiles:
ory patch identity-config {project-id} \
--add "/selfservice/flows/registration/after/oidc/hooks/0=$(cat webhook-action.json)" \
--format yaml
Read this document to learn more about choosing the authentication/registration method that triggers the action.