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.
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.
-
Open the HubSpot Developer Portal
-
Click on the 'App' tab and select an existing project or create a new project for which you want API keys and Authentication Access.
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.
To add redirect url/s for the app, click the 'Auth' tab on top of the page, and navigate to 'Redirect URLs' section.
- 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.
Before proceeding with Quick start, ensure you ave obtained the Access Token and refresh Token using the following steps:
- 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
- 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>
- Copy and paste the generated URL into your browser. This will redirect you to the HubSpot authorization page.
- 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.
- 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
}
- Store the access token securely for use in your application.
To use the HubSpot CRM Contact Connector
connector in your Ballerina application, update the .bal
file as follows:
Import the hubspot.crm.obj.contact
module.
import ballerinax/hubspot.crm.obj.contacts;
- 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 });
- 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"
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();
bal run
The Ballerina HubSpot CRM Contacts Connector
connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:
- Email-Advertising - Unsubscribe and remove customers based on email addresses of CSV-imported data.
- Event-Registration - Event registration and follow-up using CSV-imported data.
-
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. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
-
Export Github Personal access token with read package permissions as follows,
export packageUser=<Username> export packagePAT=<Personal access token>
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test
-
To build the without the tests:
./gradlew clean build -x test
-
To run tests against different environments:
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
-
To debug the package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
To debug with the Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true
As an open-source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All the contributors are encouraged to read the Ballerina Code of Conduct.
- For more information go to the
hubspot.crm.object.contacts
package. - For example demonstrations of the usage, go to Ballerina By Examples.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.