Module hubspot.crm.obj.contacts
ballerinax/hubspot.crm.obj.contacts Ballerina library
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
-
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 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.
To add redirect url/s for the app, click the 'Auth' tab on top of the page, and navigate to 'Redirect URLs' section.
Step 2. Obtain Client ID and Client Secret
- 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.
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:
-
Add the following scopes for using the Contact API:
crm.objects.contacts.write
crm.objects.contacts.read
-
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>
-
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.
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.
import ballerinax/hubspot.crm.obj.contacts;
Step 2: Instantiate a new connector
-
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"
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:
- 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.
Import
import ballerinax/hubspot.crm.obj.contacts;
Other versions
0.1.0