Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate client using OpenAPI Spec, build project, and update Package.md #2

Merged
merged 57 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1680f07
Correct module version to 1.0.0
linukaratnayake Dec 18, 2024
73b9e25
Add generated files
linukaratnayake Dec 18, 2024
5c1f377
Change Java version to 17
linukaratnayake Dec 19, 2024
a164948
Add Dependencies.toml file
linukaratnayake Dec 19, 2024
1441bf8
Add OpenAPI Spec file
linukaratnayake Dec 19, 2024
78f5e68
Add documentation to a record to avoid warnings
linukaratnayake Dec 19, 2024
5126ffa
Update 'Overview' section of Package.md
linukaratnayake Jan 2, 2025
5201696
Update 'Setup Guide' section of Package.md
linukaratnayake Jan 2, 2025
40c01ca
Modify OpenAPI spec and generate client
linukaratnayake Jan 3, 2025
1adf5fd
[Automated] Update the toml files
linukaratnayake Jan 3, 2025
944a9c7
Write tests for create, update, delete, search notes
linukaratnayake Jan 7, 2025
fd2ed8f
[Automated] Update the toml files
linukaratnayake Jan 7, 2025
9296bc6
Write tests for batch create, update, delete notes
linukaratnayake Jan 7, 2025
f49ce7b
Update sanitations.md
linukaratnayake Jan 8, 2025
330bf95
Merge pull request #1 from linukaratnayake/openapi_sanitation
linukaratnayake Jan 8, 2025
2f15624
Add license header to generated files
linukaratnayake Jan 8, 2025
9958c41
Update documentation files
linukaratnayake Jan 8, 2025
7f74c83
Complete writing tests for live server
linukaratnayake Jan 8, 2025
a3eefa5
Merge pull request #2 from linukaratnayake/tests
linukaratnayake Jan 8, 2025
918dddd
[Automated] Update the toml files
linukaratnayake Jan 8, 2025
865fb46
[Automated] Update the toml files
linukaratnayake Jan 8, 2025
57cf863
Format client.bal
linukaratnayake Jan 8, 2025
22abcc8
Update documentation files with correct markdown format
linukaratnayake Jan 8, 2025
0f2a214
Apply suggestions from code review
linukaratnayake Jan 8, 2025
925b53a
Make some suggested changes
linukaratnayake Jan 8, 2025
584d70a
Create mock tests
linukaratnayake Jan 8, 2025
d2db1ff
Create mock tests
linukaratnayake Jan 8, 2025
9b61fac
Rename OpenAPI Spec file
linukaratnayake Jan 9, 2025
dc293bd
Update gradle.properties
linukaratnayake Jan 9, 2025
12273a9
[Automated] Update the toml files
linukaratnayake Jan 9, 2025
9e45af4
Create one example for operations on a single note
linukaratnayake Jan 9, 2025
0f79eba
Create one example for operations on a batch of notes
linukaratnayake Jan 9, 2025
b63117d
Update .md files for examples
linukaratnayake Jan 9, 2025
b0d4efc
Update image URLs and add example section to .md files
linukaratnayake Jan 9, 2025
483f102
Add 'Quick Start' section to .md files
linukaratnayake Jan 9, 2025
8bfad3c
Change year from 2024 to 2025 in license file
linukaratnayake Jan 9, 2025
7bb2dfd
[Automated] Update the toml files
linukaratnayake Jan 9, 2025
1b47049
Apply suggestions from code review
linukaratnayake Jan 9, 2025
5759b65
Merge branch 'main' of https://github.com/linukaratnayake/module-ball…
linukaratnayake Jan 9, 2025
11f9689
Update .md files
linukaratnayake Jan 9, 2025
70f5299
Add suggestions regarding examples
linukaratnayake Jan 9, 2025
1fc5e67
Add test groups
linukaratnayake Jan 10, 2025
0808c4b
Add support to get environment variables for tests
linukaratnayake Jan 10, 2025
d4a6a43
Update .md files related to examples
linukaratnayake Jan 10, 2025
3debb2f
Rename .md files to README.md to display properly
linukaratnayake Jan 10, 2025
f6116cd
Add icon
linukaratnayake Jan 10, 2025
a6d1e44
Apply suggestions from code review
linukaratnayake Jan 10, 2025
1537abe
Switch order of 'Quick Start' points in .md files
linukaratnayake Jan 10, 2025
ce4c3ee
Change file to select when to run live and mock tests
linukaratnayake Jan 10, 2025
a699177
[Automated] Update the toml files
linukaratnayake Jan 10, 2025
bba9da0
Rename .md files in examples with their respective names
linukaratnayake Jan 10, 2025
8dfb11b
Change year from 2024 to 2025
linukaratnayake Jan 10, 2025
d76ce35
Add absolute path in README.md in examples
linukaratnayake Jan 16, 2025
a6389ff
Add function to initialize client
linukaratnayake Jan 16, 2025
74cb4d3
Apply suggestions from code review
linukaratnayake Jan 17, 2025
eb3e6bc
Move link from title to body in .md files
linukaratnayake Jan 17, 2025
e9c5fa2
Modify tests to run without Config.toml file
linukaratnayake 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
166 changes: 162 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,179 @@

## 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.engagement.notes` connector offers APIs to connect and interact with the [Hubspot Engagement Notes API](https://developers.hubspot.com/docs/reference/api/crm/engagements/notes) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
### Step 1: Create/Login to a HubSpot Developer Account

If you already have a HubSpot Developer Account, go to the [HubSpot developer portal](https://app.hubspot.com/).

If you don't have an account, you can sign up to a free account [here](https://developers.hubspot.com/get-started).

### Step 2 (Optional): Create a [Developer Test Account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account
linukaratnayake marked this conversation as resolved.
Show resolved Hide resolved

Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.

> **Note:** These accounts are only for development and testing purposes. In production you should not use Developer Test Accounts.

1. Go to `Test accounts` section from the left sidebar.
![test_account image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/test-account.png)

2. Click on the `Create developer test account` button on the top right corner.
![create_test_account image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/create-test-account.png)

3. In the pop-up window, provide a name for the test account and click on the `Create` button.
![create_account image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/create-account.png)

4. You will see the newly created test account in the list of test accounts.
![test_account_portal image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/test-account-portal.png)

### Step 3: Create a HubSpot App

1. Now navigate to the `Apps` section from the left sidebar and click on the `Create app` button on the top right corner.
![create_app image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/create-app.png)

2. Provide a public app name and description for your app.
![app_name_description image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/app-name-desc.png)

### Step 4: Setup authentication

1. Move to the `Auth` tab.
![config_auth image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/config-auth.png)


2. In the `Scopes` section, add the following scopes for your app using the `Add new scopes` button.
![add_scopes image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/add-scopes.png)

3. In the `Redirect URL` section, add the redirect URL for your app. This is the URL where the user will be redirected after the authentication process. You can use localhost for testing purposes. Then hit the `Create App` button.
![redirect_url image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/redirect-url.png)

### Step 5: Get the Client ID and Client Secret

Navigate to the `Auth` tab and you will see the `Client ID` and `Client Secret` for your app. Make sure to save these values.

![client_id_secret image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/client-id-secret.png)

### Step 6: Setup Authentication Flow

Before proceeding with the Quickstart, ensure you have obtained the Access Token using the following steps:

1. Create an authorization URL using the following format:

```
https://app.hubspot.com/oauth/authorize?client_id=<YOUR_CLIENT_ID>&scope=<YOUR_SCOPES>&redirect_uri=<YOUR_REDIRECT_URI>
```

Replace the `<YOUR_CLIENT_ID>`, `<YOUR_REDIRECT_URI>` and `<YOUR_SCOPES>` with your specific value.

2. Paste it in the browser and select your developer test account to intall the app when prompted.

![hubspot_auth_config_screen image](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/main/docs/setup/resources/hubspot-oauth-consent-screen.png)

3. A code will be displayed in the browser. Copy the code.

4. Run the following curl command. Replace the `<YOUR_CLIENT_ID>`, `<YOUR_REDIRECT_URI`> and `<YOUR_CLIENT_SECRET>` with your specific value. Use the code you received in the above step 3 as the `<CODE>`.

- 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=<CODE>&redirect_uri=<YOUR_REDIRECT_URI>&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=<CODE>&redirect_uri=<YOUR_REDIRECT_URI>&client_id=<YOUR_CLIENT_ID>&client_secret=<YOUR_CLIENT_SECRET>'
```

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

```json
{
"token_type": "bearer",
"refresh_token": "<Refresh Token>",
"access_token": "<Access Token>",
"expires_in": 1800
}
```

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

## Quickstart
linukaratnayake marked this conversation as resolved.
Show resolved Hide resolved

[//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.)
To use the `HubSpot Engagement Notes` connector in your Ballerina application, update the `.bal` file as shown below:

### Step 1: Import the module

Import the `hubspot.crm.engagement.notes` module and `oauth2` module.

```ballerina
import ballerina/oauth2;
import ballerinax/hubspot.crm.engagement.notes as hsengnotes;
```

### Step 2: Instantiate a new connector

1. Instantiate `hsengnotes:OAuth2RefreshTokenGrantConfig` with the obtained credentials and initialize the connector with it.

```ballerina
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;

hsengnotes:OAuth2RefreshTokenGrantConfig auth = {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
};

final hsengnotes:Client hubSpotNotes = check new ({auth});
```

2. Create a `Config.toml` file and, configure the obtained credentials in the above steps as follows:

```toml
clientId = "<Client Id>"
clientSecret = "<Client Secret>"
refreshToken = "<Refresh Token>"
```

### Step 3: Invoke the connector operation

Now, utilize the available connector operations. A sample use case is shown below.

#### Get the note with a given ID

```ballerina
public function main() returns error? {
linukaratnayake marked this conversation as resolved.
Show resolved Hide resolved
string noteId = ""; // ID of the note that needs to be read
hsengnotes:SimplePublicObjectWithAssociations readResponse = check hubSpotNotes->/[noteId]();
}
```

linukaratnayake marked this conversation as resolved.
Show resolved Hide resolved
### Step 4: Run the Ballerina application

```bash
bal run
```

## Examples

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

[//]: # (TODO: Add examples)
1. [Managing a single note](https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/tree/main/examples/manage_notes) - Operations on a single note such as creating, updating and deleting, as well as getting a list of available notes and searching for a note by its content.

2. [Working with a batch of notes](https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes/tree/main/examples/manage_notes_batch) - Operations on a batch of notes such as creating, updating and deleting, as well as getting notes by their ID.

## Build from the source

Expand Down
8 changes: 4 additions & 4 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
distribution = "2201.10.0"
org = "ballerinax"
name = "hubspot.crm.engagement.notes"
version = "0.1.0"
version = "1.0.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = []
# icon = "icon.png" # TODO: update icon.png
keywords = ["hubspot", "crm", "engagement", "notes"]
icon = "icon.png"
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.engagement.notes"

[build-options]
observabilityIncluded = true

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