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

Generated client using OpenAPI spec tool, Updated package.md, module #2

Merged
merged 37 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ae29a39
Generated client using OpenAPI spec tool, Updated package.md, module.…
roshanemoraes Jan 3, 2025
f4b7e8e
Update dependency examples/Ballerina.toml
roshanemoraes Jan 3, 2025
1ad0d99
[Automated] Update the toml files
roshanemoraes Jan 6, 2025
cc8fc19
Removed autogenerated files
roshanemoraes Jan 6, 2025
5392cc5
[Automated] Update the toml files
roshanemoraes Jan 7, 2025
bd560cf
Add Examples
roshanemoraes Jan 8, 2025
dbe7251
Update documentation
roshanemoraes Jan 9, 2025
fce22f9
Update documentations.
roshanemoraes Jan 9, 2025
b9f4556
Add resources
roshanemoraes Jan 9, 2025
37435e9
Update Auth Config
roshanemoraes Jan 9, 2025
c16c9ef
Update mock tests
roshanemoraes Jan 9, 2025
29cda6e
Update gitignore file
roshanemoraes Jan 9, 2025
533494c
Add ballerina icon
roshanemoraes Jan 9, 2025
511c4e4
Updated Ballerina.toml
roshanemoraes Jan 9, 2025
e9ed8cd
Update examples
roshanemoraes Jan 9, 2025
70ba9e3
Fix examples
roshanemoraes Jan 9, 2025
d5d46ed
Fix license
roshanemoraes Jan 9, 2025
9269608
Fix README.md
roshanemoraes Jan 9, 2025
b015517
Fix documentation
roshanemoraes Jan 9, 2025
6f37b98
Fix examples
roshanemoraes Jan 9, 2025
c518a9e
Fix tests
roshanemoraes Jan 9, 2025
8af8e6e
Fix md files
roshanemoraes Jan 9, 2025
441b6a6
Fix formating
roshanemoraes Jan 9, 2025
74c5ea0
Fix formating README
roshanemoraes Jan 9, 2025
2deb6cf
Fix typos
roshanemoraes Jan 9, 2025
cde27b4
Add md files for examples
roshanemoraes Jan 9, 2025
e4c047c
Update line lengths
roshanemoraes Jan 9, 2025
81c0167
Add Config.toml.template
roshanemoraes Jan 10, 2025
617fa9e
Fix tests
roshanemoraes Jan 10, 2025
464865b
Fix sanitation
roshanemoraes Jan 10, 2025
dde7ba2
Fix scopes
roshanemoraes Jan 10, 2025
fbf1fd2
Fix sanitations
roshanemoraes Jan 10, 2025
b539700
Fix scopes typo
roshanemoraes Jan 10, 2025
073f75c
Remove example dependencies.
roshanemoraes Jan 10, 2025
9de466f
Fix README Examples
roshanemoraes Jan 10, 2025
50a2a74
Fix typos and spacing
roshanemoraes Jan 10, 2025
4720466
Fix org name
roshanemoraes Jan 12, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ build

# Ignore Docker env file
docker.env

# Ignore examples files
**/target/
**/generated/
173 changes: 168 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,185 @@

## 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.crm.commerce.orders` package offers APIs to connect and interact with [HubSpot API for CRM Commerce Orders](https://developers.hubspot.com/docs/reference/api/crm/commerce/orders) endpoints, specifically based on [HubSpot CRM Commerce Orders REST API](https://developers.hubspot.com/docs/reference/api).

## Setup guide

[//]: # (TODO: Add detailed steps to obtain credentials and configure the module.)
To use the HubSpot Commerce Orders 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)

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.

- `crm.objects.orders.read`
- `crm.objects.orders.write`
- `crm.objects.deals.read`
- `crm.objects.deals.write`
- `crm.objects.carts.read`
- `crm.objects.commercepayments.read`
- `crm.objects.companies.read`
- `crm.objects.contacts.read`
- `crm.objects.invoices.read`
- `crm.objects.line_items.read`
- `crm.objects.quotes.read`
- `crm.objects.subscriptions.read`

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

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

![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 Commerce Orders` connector in your Ballerina application, update the `.bal` file as follows:

### Step 1: Import the module

Import the `hubspot.crm.commerce.orders` module and `oauth2` module.

```ballerina
import ballerina/oauth2;
import ballerinax/hubspot.crm.commerce.orders as orders;
```

### 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 `orders:ConnectionConfig` with the obtained credentials and initialize the connector with it.

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

final orders:ConnectionConfig config = {
roshanemoraes marked this conversation as resolved.
Show resolved Hide resolved
auth : {
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
}
};
final orders:Client baseClient = check new (config);
```

### Step 3: Invoke the connector operation

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

#### Read an order by ID

```ballerina
public function main() returns error? {
orders:CollectionResponseSimplePublicObjectWithAssociationsForwardPaging listOfOrdersResponse = check baseClient->/orders;
}
```

## Examples

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

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

## Build from the source

### Setting up the prerequisites
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.crm.commerce.orders"
version = "1.0.0"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = []
# icon = "icon.png" # TODO: update icon.png
keywords = ["hubspot","crm", "commerce", "orders"]
icon = "icon.png"
repository = "https://github.com/ballerina-platform/module-ballerinax-hubspot.crm.commerce.orders"

[build-options]
observabilityIncluded = true

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