Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
40b6304
Add the generated client and related files
ShavinAnjithaAlpha Dec 18, 2024
13a8bf1
Changing java version to 17
ShavinAnjithaAlpha Dec 23, 2024
d665c2d
Add openapi spec file
ShavinAnjithaAlpha Dec 23, 2024
a6d0d7a
Start editing overview and setup guide
ShavinAnjithaAlpha Dec 23, 2024
ccaf5c9
Add license banners to source files
ShavinAnjithaAlpha Dec 23, 2024
63d29b6
Add dependencies file
ShavinAnjithaAlpha Dec 23, 2024
641089d
[Automated] Update the toml files
ShavinAnjithaAlpha Dec 23, 2024
ebeafa5
[Automated] Update the toml files
ShavinAnjithaAlpha Dec 23, 2024
3a8f84a
Update .gitignore file
ShavinAnjithaAlpha Dec 23, 2024
d742739
Add test template file
ShavinAnjithaAlpha Dec 23, 2024
4cbf5ac
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 3, 2025
4ba0765
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 6, 2025
5615120
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 6, 2025
c6d75a6
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 6, 2025
bd94753
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 6, 2025
de3be90
Add sanitization to the openapi spec
ShavinAnjithaAlpha Jan 6, 2025
2c482c7
Regenerate the client with sanitization
ShavinAnjithaAlpha Jan 6, 2025
9a44b15
Update the overview and quickstart
ShavinAnjithaAlpha Jan 6, 2025
d158134
Add tests for client
ShavinAnjithaAlpha Jan 6, 2025
d43f5ec
Update ballerina build config
ShavinAnjithaAlpha Jan 6, 2025
6ee1035
Update ballerina build config
ShavinAnjithaAlpha Jan 6, 2025
1741b24
Add license header
ShavinAnjithaAlpha Jan 8, 2025
304bbae
Update docs and license file
ShavinAnjithaAlpha Jan 8, 2025
35eda09
Update sanitization file
ShavinAnjithaAlpha Jan 8, 2025
ca2d40c
Change the test cases for improved code quality
ShavinAnjithaAlpha Jan 8, 2025
dd0ba15
Merge remote-tracking branch 'origin/main'
ShavinAnjithaAlpha Jan 8, 2025
32fc34e
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 8, 2025
958575e
Fix issues in documentation and source files
ShavinAnjithaAlpha Jan 9, 2025
ee4fb66
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 9, 2025
7e16947
Add two examples
ShavinAnjithaAlpha Jan 9, 2025
b402a36
Format code and fix issues in docs
ShavinAnjithaAlpha Jan 9, 2025
477b688
Update build files and example docs
ShavinAnjithaAlpha Jan 9, 2025
24908e4
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 9, 2025
97943c1
Create a mock service for some endpoints
ShavinAnjithaAlpha Jan 10, 2025
6be4f95
Fix issues and format docs and some source file
ShavinAnjithaAlpha Jan 10, 2025
b4a5d5f
Add auto-generated license header
ShavinAnjithaAlpha Jan 14, 2025
27edf66
Rename example's readme files
ShavinAnjithaAlpha Jan 14, 2025
7bbd1ff
Fix issue in example codes
ShavinAnjithaAlpha Jan 14, 2025
d2f463e
Add a new line to end of files
ShavinAnjithaAlpha Jan 14, 2025
97a70a5
Restructure the test code
ShavinAnjithaAlpha Jan 14, 2025
aed5aa0
Change setup guide url path
ShavinAnjithaAlpha Jan 14, 2025
da7fda7
[Automated] Update the toml files
ShavinAnjithaAlpha Jan 14, 2025
00e1c5d
Finish the mock service and add mock tests
ShavinAnjithaAlpha Jan 14, 2025
138eb76
Change image URLs to GitHub URLs
ShavinAnjithaAlpha Jan 16, 2025
73fa8d6
Change image URLs to GitHub URLs
ShavinAnjithaAlpha Jan 16, 2025
1d2d4f4
Change image URLs
ShavinAnjithaAlpha Jan 16, 2025
1a70da4
Modify the example codes
ShavinAnjithaAlpha Jan 17, 2025
0bf20d4
Merge remote-tracking branch 'origin/main'
ShavinAnjithaAlpha Jan 17, 2025
811cf48
Change arguments to main function
ShavinAnjithaAlpha Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ generated/
*Ballerina.lock
.ballerina
**/Config.toml
**/target/
**/generated/

# Ignore Gradle project-specific cache directory
.gradle
Expand All @@ -56,3 +58,11 @@ build

# Ignore Docker env file
docker.env

# Test config file
ballerina/tests/Config.toml

# Data files
*.csv


156 changes: 152 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,169 @@

## Overview

[//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.)
[HubSpot](https://www.hubspot.com) 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](https://api.hubapi.com/crm/v3/objects/contacts) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/crm/objects/contacts).

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

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
To use the HubSpot connector, you must have access to the HubSpot API through a [HubSpot developer account](https://developers.hubspot.com/get-started) and a project under it. If you do not have a HubSpot Developer account, you can sign up for one [here](https://app.hubspot.com/signup-hubspot/developers?_ga=2.207749649.2047916093.1734412948-232493525.1734412948&step=landing_page).

### Step 1: Create a HubSpot Developer Project

1. Open the [HubSpot Developer Portal](https://app.hubspot.com/login/?loginRedirectUrl=https%3A%2F%2Fapp.hubspot.com%2Fsignup-hubspot%2Fdevelopers%3F_ga%3D2.269102326.624948025.1734413225-1764281074.1734413225%26step%3Dlanding_page)

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 Page](<docs/setup/resources/hubspot-app-home.png>)

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](docs/setup/resources/hubspot-new-app-info.png)

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](docs/setup/resources/hubspot-new-app-auth.png)

![HubSpot New App Redirect URL](docs/setup/resources/hubspot-new-app-redirect-url.png)

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

![HuSpot New App Client Id And Secret](docs/setup/resources/hubspot-new-app-client-id-secret.png)

### 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](https://developers.hubspot.com/beta-docs/reference/api), select the API you have and go through the operation.

You will see the scope has defined below way

![HubSpot New App Scopes](docs/setup/resources/hubspot-new-app-scopes.png)

2. 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>
```
3. Copy and paste the generated URL into your browser. This will redirect you to the HubSpot authorization page.

![HubSpot OAuth Consent Screen](docs/setup/resources/hubspot-oauth-consent-screen.png)

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:
```bash
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:
```bash
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.

```json
{
"token_type": "bearer",
"refresh_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"expires_in": 1800
}
```

6. Store the access token securely for use in your application.


## Quickstart

[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.)
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.

````ballerina
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.

````ballerina
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:

````toml
[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**

```ballerina
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**

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

### Step 4: Run the Ballerina application

````bash
bal run
````

## Examples

The `Ballerina HubSpot CRM Contacts Connector` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-hubspot.crm.object.contacts/tree/main/examples/), covering the following use cases:

[//]: # (TODO: Add examples)
1. [Email-Advertising](./examples/Email-Advertising/) - Unsubscribe and remove customers based on email addresses of CSV-imported data.
2. [Event-Registration](./examples/Event-Registration/) - Event registration and follow-up using CSV-imported data.

## Build from the source

Expand Down
10 changes: 5 additions & 5 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
distribution = "2201.10.0"
org = "ballerinax"
name = "hubspot.crm.object.contacts"
name = "hubspot.crm.obj.contacts"
version = "0.1.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = []
# icon = "icon.png" # TODO: update icon.png
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.object.contacts"
keywords = ["hubspot", "customer", "management", "connector", "crm"]
icon = "icon.png"
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.obj.contacts"

[build-options]
observabilityIncluded = true

[platform.java21]
[platform.java17]
graalvmCompatible = true
Loading