Skip to content

Latest commit

 

History

History
270 lines (172 loc) · 10.6 KB

File metadata and controls

270 lines (172 loc) · 10.6 KB

Ballerina Ballerina HubSpot CRM Contacts Connector connector

Build Trivy GraalVM Check GitHub Last Commit GitHub Issues

Overview

HubSpot is an AI-powered customer relationship management (CRM) platform.

The ballerinax/module-ballerinax-hubspot.crm.obj.contacts package offers APIs to connect and interact with the HubSpot Contact API endpoints, specifically based on the HubSpot REST API.

Using this API, users can develop applications easily that enables you to manage contacts easily.

Setup guide

To use the HubSpot connector, you must have access to the HubSpot API through a HubSpot developer account and a project under it. If you do not have a HubSpot Developer account, you can sign up for one here.

Step 1: Create a HubSpot Developer Project

  1. Open the HubSpot Developer Portal

  2. Click on the 'App' tab and select an existing project or create a new project for which you want API keys and Authentication Access.

hubspot-app-home

In order to create a new poject, you must provide a public app name and a redirect url/s. Optionally you can add a app logo and a description for the app.

hubspot-new-app-info

To add redirect url/s for the app, click the 'Auth' tab on top of the page, and navigate to 'Redirect URLs' section.

hubspot-new-app-auth

hubspot-new-app-redirect-url

Setp 2. Obtain Client ID and Client Secret.

  1. After completing the project setup, you will be provided with your client id and client secret. Make sure to save the provided client id and client secret.

hubspot-new-app-client-id-secret

2. Setup OAuth 2.0 Flow

Before proceeding with Quick start, ensure you ave obtained the Access Token and refresh Token using the following steps:

  1. Add necessaryscopes for your app based on API your using. Go to the relevate API reference, select the API you have and go through the operation.

You will see the scope has defined below way

hubspot-new-app-scopes

  1. Obtained the authorization URL (Install URL) from the Auth Section under 'Sample install URL (OAuth)' section. It will be in this format:
https://app.hubspot.com/oauth/authorize?client_id=<client_id>&redirect_uri=<redirect_url>&scope=<scopes>
  1. Copy and paste the generated URL into your browser. This will redirect you to the HubSpot authorization page.

hubspot-oauth-consent-screen

  1. Once you authorize, you will be redirected to your specified redirect URI with an authorization code in the URL.

Note: Store the authorization code and use it promptly as it expires quickly.

  1. Use the obtained authorization code to run the following curl command, replacing <your_client_id>, <your_redirect_url>, and <your_authorization_code> with your specific values:
  • Linux/MacOS:
curl --request POST \
  --url https://api.hubapi.com/oauth/v1/token \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'grant_type=authorization_code&code=<your_authorization_code>&redirect_uri=<your_redirect_url>&client_id=<your_client_id>&client_secret=<your_client_secret>'
  • Windows:
curl --request POST \
 --url https://api.hubapi.com/oauth/v1/token ^
 --header 'content-type: application/x-www-form-urlencoded' ^
 --data 'grant_type=authorization_code&code=<your_authorization_code>&redirect_uri=<your_redirect_url>&client_id=<your_client_id>&client_secret=<your_client_secret>'

This command will return the access token and refresh token necessary for API calls.

{
 "token_type": "bearer",
 "refresh_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 "expires_in": 1800
}
  1. Store the access token securely for use in your application.

Quickstart

To use the HubSpot CRM Contact Connector connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Import the hubspot.crm.obj.contact module.

import ballerinax/hubspot.crm.obj.contacts;

Step 2: Instantiate a new connector

  1. Create a OAuth2RefreshTokenGrantConfig with the obtained access token and initialize the connector with it.
configurable OAuth2RefreshTokenGrantConfig & readonly auth = ?;

final contacts:Client hubSpotContacts = check new ({ auth });
  1. Create a Config.toml file and, configure the obtained credentials in the above steps as follows:
[auth]
clientId = "<Client Id>"
clientSecret =  "<Client Secret>"
refreshToken = "<Refresh Token>"
credentialBearer =  "POST_BODY_BEARER"

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

Create a contact

contacts:SimplePublicObjectInputForCreate newContact = {
    associations: [
        {
            to: {
                id: "associated_id"
            }
        }
    ],
    objectWriteTraceId: "object_write_trace_id",
    properties: {
        "sample_property": "sample_value"
    }
};

contacts:SimplePublicObject response = check hubSpotContacts->/.post(newContact);

List contacts

contacts:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging contacts = check hubSpotContacts->/.get();

Step 4: Run the Ballerina application

bal run

Examples

The Ballerina HubSpot CRM Contacts Connector connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Email-Advertising - Unsubscribe and remove customers based on email addresses of CSV-imported data.
  2. Event-Registration - Event registration and follow-up using CSV-imported data.

Build from the source

Setting up the prerequisites

  1. Download and install Java SE Development Kit (JDK) version 21. You can download it from either of the following sources:

    Note: After installation, remember to set the JAVA_HOME environment variable to the directory where JDK was installed.

  2. Download and install Ballerina Swan Lake.

  3. Download and install Docker.

    Note: Ensure that the Docker daemon is running before executing any tests.

  4. Export Github Personal access token with read package permissions as follows,

    export packageUser=<Username>
    export packagePAT=<Personal access token>

Build options

Execute the commands below to build from the source.

  1. To build the package:

    ./gradlew clean build
  2. To run the tests:

    ./gradlew clean test
  3. To build the without the tests:

    ./gradlew clean build -x test
  4. To run tests against different environments:

    ./gradlew clean test -Pgroups=<Comma separated groups/test cases>
  5. To debug the package with a remote debugger:

    ./gradlew clean build -Pdebug=<port>
  6. To debug with the Ballerina language:

    ./gradlew clean build -PbalJavaDebug=<port>
  7. Publish the generated artifacts to the local Ballerina Central repository:

    ./gradlew clean build -PpublishToLocalCentral=true
  8. Publish the generated artifacts to the Ballerina Central repository:

    ./gradlew clean build -PpublishToCentral=true

Contribute to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All the contributors are encouraged to read the Ballerina Code of Conduct.

Useful links