Skip to content
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ The `ballerinax/hubspot.crm.object.lineitems` package offers APIs to connect and

# Setup guide

To use the HubSpot Properties 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.
To use the HubSpot Line items 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 01 : Create/ Login to a HubSpot Developer Account

If you have an account already go to the [Hubspot account portal](https://app.hubspot.com/myaccounts-beta)

If you don't have a developer account, register for a free Hubspot developer account.[(click here)](https://app.hubspot.com/signup-hubspot/developers?_ga=2.207749649.2047916093.1734412948-232493525.1734412948&step=landing_page)

#### Step 02 (Optional) : Create a [Developer test account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts):
Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
#### Step 02 (Optional) : Create a Developer test account:
Within app developer accounts, you can create [Developer test accounts](https://developers.hubspot.com/beta-docs/getting-started/account-types#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.

Expand Down Expand Up @@ -51,7 +51,11 @@ Click on `Create App`
1. Move to the Auth tab.
![alt text](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.lineitems/main/docs/setup/resources/image.png)

2. In the Scopes section, add necessary scopes for your app using the "Add new scope" button.
2. In the Scopes section, add necessary scopes for your app using the "Add new scope" button. For line items API connector we will have to add the following 3 scopes in addition to the existing `oauth` scope.
* `e-commerce`
* `crm.objects.line_items.read`
* `crm.objects.line_items.write`

![Hubspot set scope](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.lineitems/main/docs/setup/resources/image-2.png)

3. Add your Redirect URI in the relevant section. You can also use localhost addresses for local development purposes. Click Create App.
Expand All @@ -73,16 +77,17 @@ Before proceeding with the Quickstart, ensure you have obtained the Access Token
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.
Replace `<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 install the app when prompted.

2. Paste it in the browser and select your developer test account to intall the app when prompted.
3. A code will be displayed in the browser. Copy the code.

```
Received code: na1-129d-860c-xxxx-xxxx-xxxxxxxxxxxx
```

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>`.
4. Run the following curl command. Replace `<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

Expand Down Expand Up @@ -121,7 +126,7 @@ To use the `HubSpot CRM Object Line items` connector in your Ballerina applicati

#### Step 1: Import the module

Import the `hubspot.crm.object.lineitems` module and `oauth2` module.
Import the `hubspot.crm.obj.lineitems` module and `oauth2` module.

```ballerina
import ballerinax/hubspot.crm.obj.lineitems as hslineitems;
Expand Down
21 changes: 13 additions & 8 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ The `ballerinax/hubspot.crm.object.lineitems` package offers APIs to connect and

# Setup guide

To use the HubSpot Properties 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.
To use the HubSpot Line items 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 01 : Create/ Login to a HubSpot Developer Account

If you have an account already go to the [Hubspot account portal](https://app.hubspot.com/myaccounts-beta)

If you don't have a developer account, register for a free Hubspot developer account.[(click here)](https://app.hubspot.com/signup-hubspot/developers?_ga=2.207749649.2047916093.1734412948-232493525.1734412948&step=landing_page)

#### Step 02 (Optional) : Create a [Developer test account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts):
Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
#### Step 02 (Optional) : Create a Developer test account:
Within app developer accounts, you can create [Developer test accounts](https://developers.hubspot.com/beta-docs/getting-started/account-types#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.

Expand Down Expand Up @@ -44,7 +44,11 @@ Click on `Create App`
1. Move to the Auth tab.
![alt text](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.lineitems/main/docs/setup/resources/image.png)

2. In the Scopes section, add necessary scopes for your app using the "Add new scope" button.
2. In the Scopes section, add necessary scopes for your app using the "Add new scope" button. For line items API connector we will have to add the following 3 scopes in addition to the existing `oauth` scope.
* `e-commerce`
* `crm.objects.line_items.read`
* `crm.objects.line_items.write`

![Hubspot set scope](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.lineitems/main/docs/setup/resources/image-2.png)

3. Add your Redirect URI in the relevant section. You can also use localhost addresses for local development purposes. Click Create App.
Expand All @@ -66,16 +70,17 @@ Before proceeding with the Quickstart, ensure you have obtained the Access Token
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.
Replace `<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 install the app when prompted.

2. Paste it in the browser and select your developer test account to intall the app when prompted.
3. A code will be displayed in the browser. Copy the code.

```
Received code: na1-129d-860c-xxxx-xxxx-xxxxxxxxxxxx
```

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>`.
4. Run the following curl command. Replace `<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

Expand Down Expand Up @@ -114,7 +119,7 @@ To use the `HubSpot CRM Object Line items` connector in your Ballerina applicati

#### Step 1: Import the module

Import the `hubspot.crm.object.lineitems` module and `oauth2` module.
Import the `hubspot.crm.obj.lineitems` module and `oauth2` module.

```ballerina
import ballerinax/hubspot.crm.obj.lineitems as hslineitems;
Expand Down
21 changes: 13 additions & 8 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ The `ballerinax/hubspot.crm.object.lineitems` package offers APIs to connect and

# Setup guide

To use the HubSpot Properties 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.
To use the HubSpot Line items 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 01 : Create/ Login to a HubSpot Developer Account

If you have an account already go to the [Hubspot account portal](https://app.hubspot.com/myaccounts-beta)

If you don't have a developer account, register for a free Hubspot developer account.[(click here)](https://app.hubspot.com/signup-hubspot/developers?_ga=2.207749649.2047916093.1734412948-232493525.1734412948&step=landing_page)

#### Step 02 (Optional) : Create a [Developer test account](https://developers.hubspot.com/beta-docs/getting-started/account-types#developer-test-accounts):
Within app developer accounts, you can create developer test accounts to test apps and integrations without affecting any real HubSpot data.
#### Step 02 (Optional) : Create a Developer test account:
Within app developer accounts, you can create [Developer test accounts](https://developers.hubspot.com/beta-docs/getting-started/account-types#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.

Expand Down Expand Up @@ -43,7 +43,11 @@ Click on `Create App`
1. Move to the Auth tab.
![alt text](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.lineitems/main/docs/setup/resources/image.png)

2. In the Scopes section, add necessary scopes for your app using the "Add new scope" button.
2. In the Scopes section, add necessary scopes for your app using the "Add new scope" button. For line items API connector we will have to add the following 3 scopes in addition to the existing `oauth` scope.
* `e-commerce`
* `crm.objects.line_items.read`
* `crm.objects.line_items.write`

![Hubspot set scope](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-hubspot.crm.object.lineitems/main/docs/setup/resources/image-2.png)

3. Add your Redirect URI in the relevant section. You can also use localhost addresses for local development purposes. Click Create App.
Expand All @@ -65,16 +69,17 @@ Before proceeding with the Quickstart, ensure you have obtained the Access Token
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.
Replace `<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 install the app when prompted.

2. Paste it in the browser and select your developer test account to intall the app when prompted.
3. A code will be displayed in the browser. Copy the code.

```
Received code: na1-129d-860c-xxxx-xxxx-xxxxxxxxxxxx
```

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>`.
4. Run the following curl command. Replace `<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>`.

- Ballerina Program

Expand Down Expand Up @@ -115,7 +120,7 @@ To use the `HubSpot CRM Object Line items` connector in your Ballerina applicati

#### Step 1: Import the module

Import the `hubspot.crm.object.lineitems` module and `oauth2` module.
Import the `hubspot.crm.obj.lineitems` module and `oauth2` module.

```ballerina
import ballerinax/hubspot.crm.obj.lineitems as hslineitems;
Expand Down
35 changes: 18 additions & 17 deletions ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ import ballerina/os;
import ballerina/test;

final boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true";
final string serviceUrl = isLiveServer ? "https://api.hubapi.com/crm/v3/properties" : "http://localhost:9090";
final string serviceUrl = isLiveServer ? "https://api.hubapi.com/crm/v3/objects/line_items" : "http://localhost:9090";

final string clientId = os:getEnv("HUBSPOT_CLIENT_ID");
final string clientSecret = os:getEnv("HUBSPOT_CLIENT_SECRET");
final string refreshToken = os:getEnv("HUBSPOT_REFRESH_TOKEN");

final Client hsLineItems = check initClient();

isolated function initClient() returns Client|error {
if isLiveServer {
OAuth2RefreshTokenGrantConfig auth = {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
clientId,
clientSecret,
refreshToken,
credentialBearer: oauth2:POST_BODY_BEARER
};
return check new ({auth}, serviceUrl);
Expand All @@ -51,8 +52,8 @@ final string testUpdatedPrice = "4500.00";
final string testUpdatedQuantity = "4";
final string testUpdatedName = "Updated Line Item 01";
final string testDeal_id = "31232284502";
string lineitem_id = "";
string batch_id = "";
string lineitemID = "";
string batchID = "";

@test:Config {
groups: ["live_tests", "mock_tests"]
Expand Down Expand Up @@ -92,7 +93,7 @@ function testPostLineofItems() returns error? {
}
);
test:assertTrue(response?.id != "");
lineitem_id = response.id;
lineitemID = response.id;
}

@test:Config {
Expand All @@ -101,8 +102,8 @@ function testPostLineofItems() returns error? {
enable: isLiveServer
}
function testGetlineItemByID() returns error? {
SimplePublicObjectWithAssociations response = check hsLineItems->/[lineitem_id].get();
test:assertTrue(response?.id == lineitem_id);
SimplePublicObjectWithAssociations response = check hsLineItems->/[lineitemID].get();
test:assertTrue(response?.id == lineitemID);
}

@test:Config {
Expand All @@ -111,7 +112,7 @@ function testGetlineItemByID() returns error? {
enable: isLiveServer
}
function testUpdateLineItemProperties() returns error? {
SimplePublicObject response = check hsLineItems->/[lineitem_id].patch(
SimplePublicObject response = check hsLineItems->/[lineitemID].patch(
payload = {
"objectWriteTraceId": "2",
"properties": {
Expand All @@ -121,7 +122,7 @@ function testUpdateLineItemProperties() returns error? {
}
}
);
test:assertTrue(response?.id == lineitem_id);
test:assertTrue(response?.id == lineitemID);
test:assertTrue(response?.properties["price"] == testUpdatedPrice);
}

Expand All @@ -131,7 +132,7 @@ function testUpdateLineItemProperties() returns error? {
enable: isLiveServer
}
function testDeleteLineItem() returns error? {
http:Response response = check hsLineItems->/[lineitem_id].delete();
http:Response response = check hsLineItems->/[lineitemID].delete();
test:assertTrue(response.statusCode == 204);
}

Expand Down Expand Up @@ -169,7 +170,7 @@ function testCreateBatchofLineItems() returns error? {
}
);
test:assertTrue(response?.results != [], "Line items not found");
batch_id = response.results[0].id;
batchID = response.results[0].id;
}

@test:Config {
Expand All @@ -185,15 +186,15 @@ function testReadBatchLineItems() returns error? {
],
"inputs": [
{
"id": batch_id
"id": batchID
}
],
"properties": [
"quantity"
]
}
);
test:assertTrue(response?.results[0].id == batch_id);
test:assertTrue(response?.results[0].id == batchID);
}

@test:Config {
Expand All @@ -206,7 +207,7 @@ function testUpdateBatchLineItems() returns error? {
payload = {
"inputs": [
{
"id": batch_id,
"id": batchID,
"properties": {
"price": testUpdatedPrice,
"quantity": testUpdatedQuantity,
Expand Down Expand Up @@ -274,7 +275,7 @@ function testArchiveBatchLineItems() returns error? {
payload = {
"inputs": [
{
"id": batch_id
"id": batchID
}
]

Expand Down
22 changes: 11 additions & 11 deletions examples/customer-order-fulfillment/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;

string batch_id = "";
string batchID = "";
string[] batchitemIds = []; // Array to store batch item IDs

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

Expand Down Expand Up @@ -154,15 +154,15 @@ public function main() returns error? {
}

//Step 2:After creating the batch, the warehouse manager verifies its contents to ensure accuracy.
foreach string batch_id in batchitemIds {
foreach string batchID in batchitemIds {
hslineitems:BatchResponseSimplePublicObject batchitems_response = check hsLineItems->/batch/read.post(
payload = {
"propertiesWithHistory": [
"name"
],
"inputs": [
{
"id": batch_id
"id": batchID
}
],
"properties": [
Expand Down Expand Up @@ -191,11 +191,11 @@ public function main() returns error? {
io:println("Total number of items found: ", searchitems_response.total);

//Step 4: Update item quantities as per customer request before proceeding with the order.
foreach string batch_id in batchitemIds {
foreach string batchID in batchitemIds {
hslineitems:BatchInputSimplePublicObjectBatchInput update_payload = {
"inputs": [
{
"id": batch_id,
"id": batchID,
"properties": {
"quantity": "2"
}
Expand All @@ -207,18 +207,18 @@ public function main() returns error? {
}

//Step 5: Delete the batch of items from the inventory after the order is fulfilled.
foreach string batch_id in batchitemIds {
foreach string batchID in batchitemIds {
http:Response delete_response = check hsLineItems->/batch/archive.post(
payload = {
"inputs": [
{
"id": batch_id
"id": batchID
}
]

}
);
io:println(delete_response.statusCode, ": Item with ID: ", batch_id, " deleted successfully");
io:println(delete_response.statusCode, ": Item with ID: ", batchID, " deleted successfully");
}

}
Loading
Loading