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, Update Setup Guide and Quickstart #2

Merged
merged 66 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
61311f5
Add the openapi specification:
lckariyawasam Dec 17, 2024
ffa8f07
Add files generated by openapi tool
lckariyawasam Dec 17, 2024
5008ee8
[Automated] Update the toml files
lckariyawasam Dec 18, 2024
c7bbdea
Add documentation on sanitizations
lckariyawasam Dec 18, 2024
7275a9e
[Automated] Update the toml files
lckariyawasam Dec 18, 2024
626b374
Change java version to java17
lckariyawasam Dec 18, 2024
7faefdf
Add tests for two endpoints
lckariyawasam Dec 19, 2024
c78afe1
[Automated] Update the toml files
lckariyawasam Dec 20, 2024
94adf35
Update Setup Guide and Quickstart
lckariyawasam Dec 20, 2024
b7bfb56
Add sanitation to OpenAPI spec and update the documentation
lckariyawasam Jan 2, 2025
28c0909
Update ballerina/Package.md
lckariyawasam Jan 2, 2025
c180ec3
Add sanitation to OpenAPI spec, regenerate types and update documenta…
lckariyawasam Jan 2, 2025
9c6c17e
Change test case for /statistics/histogram endpoint to fix error
lckariyawasam Jan 3, 2025
2979a2f
Add test case for GET /emails endpoint
lckariyawasam Jan 3, 2025
014bc1a
Add testcases to create and retrieve emails from API
lckariyawasam Jan 3, 2025
552fe02
Add test for clone endpoint
lckariyawasam Jan 3, 2025
6bdc148
Remove assertions checking for email ids from /emails endpoint test
lckariyawasam Jan 3, 2025
4b9d943
Add testcase for deleting emails using API
lckariyawasam Jan 3, 2025
62f75ba
Add testcase to check email draft endpoint
lckariyawasam Jan 3, 2025
dcc4d2f
[Automated] Update the toml files
lckariyawasam Jan 6, 2025
add7c40
Add testcase for adding and retrieving draft for emails
lckariyawasam Jan 6, 2025
150ec34
Update Hubspot introduction of package.md
lckariyawasam Jan 6, 2025
ebceaea
Add testcase for reseting email draft
lckariyawasam Jan 6, 2025
d4bb9db
Change server base url and update API paths
lckariyawasam Jan 6, 2025
b43367c
Add sanitation to OpenAPI spec and update documentation
lckariyawasam Jan 6, 2025
a8e6ce4
Add testcases for updating, retrieving and restoring revisions
lckariyawasam Jan 6, 2025
4bc5a24
Update ballerina/Package.md
lckariyawasam Jan 7, 2025
35b600f
Format ballerina/tests/test.bal to improve readability
lckariyawasam Jan 7, 2025
d522947
Refactor ballerina/test/test.bal
lckariyawasam Jan 7, 2025
9d77b9d
Update docs/spec/sanitations.md
lckariyawasam Jan 7, 2025
775c637
Remove localserver reference from /ballerina/test/test.bal
lckariyawasam Jan 7, 2025
eb7ffec
[Automated] Update the toml files
lckariyawasam Jan 7, 2025
76b005c
Add sanitation to openAPI specification and update documentation
lckariyawasam Jan 7, 2025
c3e1ec2
Update the server url to include common prefix
lckariyawasam Jan 7, 2025
ac499fd
Add licencing header to ballerina/test/test.bal
lckariyawasam Jan 8, 2025
af71361
Add example use case of connector
lckariyawasam Jan 8, 2025
55362d7
Update ballerina/tests/test.bal
lckariyawasam Jan 8, 2025
855bf64
Add keywords to build-config/resources/Ballerina.toml
lckariyawasam Jan 8, 2025
23176ec
Format docs/spec/sanitations.md
lckariyawasam Jan 8, 2025
a0f8ff7
Update docs/spec/sanitations.md
lckariyawasam Jan 8, 2025
14a951d
Format ballerina/test/test.bal
lckariyawasam Jan 8, 2025
e8f97e7
Update README.md and ballerina/package.md
lckariyawasam Jan 8, 2025
479854f
Cleanup TODO in README and ballerina/Package.md
lckariyawasam Jan 8, 2025
a8f4e2d
Update README.md
lckariyawasam Jan 8, 2025
f8b3589
Apply suggestions from code review
lckariyawasam Jan 9, 2025
529bba1
Update ballerina/Package.md to be consistent with README.md
lckariyawasam Jan 9, 2025
6c07e50
Change example name from camelCase to snake_case
lckariyawasam Jan 9, 2025
1b026b4
[Automated] Update the toml files
lckariyawasam Jan 9, 2025
4c5d971
Remove local dependency in the /examples
lckariyawasam Jan 9, 2025
2a27e9e
Update examples/bulk_change_reply_email/main.bal
lckariyawasam Jan 9, 2025
a6ad5b8
Add another example use case to /examples
lckariyawasam Jan 9, 2025
57a4a4f
Update examples/email_stat_logger/Dependencies.toml
lckariyawasam Jan 9, 2025
4f5685a
Apply suggestions from code review
lckariyawasam Jan 9, 2025
74ec515
Update README to replace relative links
lckariyawasam Jan 9, 2025
6917739
Add content to ballerina/Module.md and update ballerina/Package.md
lckariyawasam Jan 9, 2025
9085f99
Update README, ballerina/Package.md and ballerina/Module.md
lckariyawasam Jan 9, 2025
c041a33
[Automated] Update the toml files
lckariyawasam Jan 9, 2025
7e34ba6
Add mock tests
lckariyawasam Jan 9, 2025
cd86474
Update README, ballerina/Module.md and ballerina/Package.md
lckariyawasam Jan 10, 2025
efbe9e8
Apply suggestions from code review to ballerina/tests/test.bal
lckariyawasam Jan 10, 2025
207b239
Add license header generation to sanitations.md
lckariyawasam Jan 10, 2025
eb32701
Update example/email_stat_logger/main.bal
lckariyawasam Jan 10, 2025
ab5defc
Update README, ballerina/Module.md and ballerina/Package.md
lckariyawasam Jan 10, 2025
7d34cc8
Update ballerina/tests/test.bal
lckariyawasam Jan 10, 2025
2c22c7e
Update README, ballerina/Module.md and ballerina/Package.md
lckariyawasam Jan 10, 2025
5520ff8
Update ballerina/tests/mock_service.bal
lckariyawasam Jan 10, 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
179 changes: 174 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,190 @@

## 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/hubspot.marketing.emails` package offers APIs to connect and interact with the [HubSpot Marketing Emails API](https://developers.hubspot.com/docs/reference/api/marketing/emails/marketing-emails) endpoints, specifically based on the [HubSpot REST API](https://developers.hubspot.com/docs/reference/api/overview).

Using this API, users can develop applications easily that enables you to track marketing emails.

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
To use the HubSpot Marketing Events connector, you must have access to the HubSpot API through a HubSpot developer account and a HubSpot App under it. Therefore you need to register for a developer account at HubSpot if you don't have one already.

### Step 1: Create/Login to a HubSpot Developer Account

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

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

### Step 2 (Optional): Create a Developer Test Account

Within app developer accounts, you can create [developer test account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts) under your account 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 Account section from the left sidebar.

![Hubspot Developer Portal](./docs/setup/resources/test_acc_1.png)

lckariyawasam marked this conversation as resolved.
Show resolved Hide resolved
2. Click Create developer test account.

![Hubspot Developer Test Account](./docs/setup/resources/test_acc_2.png)

3. In the dialogue box, give a name to your test account and click create.

![Hubspot Developer Test Account](./docs/setup/resources/test_acc_3.png)

### Step 3: Create a HubSpot App under your account.

1. In your developer account, navigate to the "Apps" section. Click on "Create App"

![Hubspot Create App](./docs/setup/resources/create_app_1.png )

2. Provide the necessary details, including the app name and description.

### Step 4: Configure the Authentication Flow.

1. Move to the Auth Tab. (Second tab next to App Info)

![Hubspot Developer Config Auth](./docs/setup/resources/auth_section.png )

2. In the Scopes section, add the following scope for your app using the "Add new scope" button.

* `content`

![Hubspot Developer App Add Scopes](./docs/setup/resources/scopes.png )

4. Add your Redirect URI in the relevant section. You can also use `localhost` addresses for local development purposes. Click Create App.

![Hubspot Create Developer App](./docs/setup/resources/create_app_final.png )

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

- Navigate to the Auth section of your app. Make sure to save the provided Client ID and Client Secret.

![Hubspot Get Credentials](./docs/setup/resources/get_credentials.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.

> **NOTE:** If you are using a `localhost` redirect url, make sure to have a listener running at the relevant port before executing the next step.

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

![Hubspot Get Auth Code](./docs/setup/resources/install_app.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

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

### Step 1: Import the module

Import the `hubspot.marketing.emails` module and `oauth2` module.

```ballerina
import ballerinax/hubspot.marketing.emails as hsmemails;
import ballerina/oauth2;
```

### Step 2: Instantiate a new connector

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

2. Instantiate a `hsmevents:ConnectionConfig` with the obtained credentials and initialize the connector with it.

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

final hsmemails:ConnectionConfig hsmeventsConfig = {
auth : {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
};

final hsmemails:Client hsmevents = check new (hsmeventsConfig, "https://api.hubapi.com/marketing/v3/emails");
lckariyawasam marked this conversation as resolved.
Show resolved Hide resolved
```

### Step 3: Invoke the connector operation

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

#### Create a Marketing Event

```ballerina
public function main() returns error? {
hsmemails:AggregateEmailStatistics emailStatistics = check hubspotClient->/marketing/v3/emails/statistics/list({},
{
startTimestamp: "2024-12-12T04:27:02Z",
endTimestamp: "2024-12-19T04:27:02Z"
});
}
```

## Examples

The `HubSpot Marketing Emails` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-hubspot.marketing.emails/tree/main/examples/), covering the following use cases:
The `Hubspot Marketing Emails` connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering use cases:

1. [Bulk Change Reply To Email](./examples/bulk_change_reply_email/) - Change the Reply To and Custom Reply To email address of all draft emails

2. [Marketing Email Statistics Logger](./examples/email_stat_logger/) - Retrieve and log the statistics of marketing emails during a specific time period.
lckariyawasam marked this conversation as resolved.
Show resolved Hide resolved

[//]: # (TODO: Add examples)

## Build from the source

Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ name = "hubspot.marketing.emails"
version = "0.1.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = []
# icon = "icon.png" # TODO: update icon.png
keywords = ["hubspot", "crm", "marketing", "emails"]
# icon = "icon.png" # TODO: Add icon
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.marketing.emails"

[build-options]
observabilityIncluded = true

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