Module hubspot.crm.obj.contacts

ballerinax/hubspot.crm.obj.contacts Ballerina library

0.1.0

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 project, 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

Step 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 the following scopes for using the Contact API:

    • crm.objects.contacts.write
    • crm.objects.contacts.read
  2. Obtain 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>
    
  3. Copy and paste the generated URL into your browser. This will redirect you to the HubSpot authorization page.

    hubspot-oauth-consent-screen

  4. 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.

  5. 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:
    Copy
    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:
    Copy
    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.

    Copy
    {
    "token_type": "bearer",
    "refresh_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "expires_in": 1800
    }
  6. 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 ballerinax/hubspot.crm.obj.contacts module.

Copy
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.

    Copy
    configurable OAuth2RefreshTokenGrantConfig & readonly auth = ?;
    
    final contacts:Client hubSpotContacts = check new ({ auth });
  2. Create a Config.toml file and, configure the obtained credentials in the above steps as follows:

    Copy
    [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

Copy
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

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

Step 4: Run the Ballerina application

Copy
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.

Import

import ballerinax/hubspot.crm.obj.contacts;Copy

Metadata

Released date: 30 days ago

Version: 0.1.0

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.10.0

GraalVM compatible: Yes


Pull count

Total: 0

Current verison: 0


Weekly downloads


Source repository


Keywords

hubspot

customer

management

connector

crm


Contributors

Other versions

0.1.0