General implementation of HubSpot CRM API in tiny Kotlin SDK.
π Currently in progress, send issues or pull requests ππΌ
π Install from official Maven repository with org.boomevents:hubspot-sdk:$VERSION
Feature | List | Read | Create | Change | Delete |
---|---|---|---|---|---|
Company | β | β | β | β | β |
Custom objects | β | β | β | β | β |
Deal | β | β | β | β | β |
Contact | β | β | β | β | β |
Associations | β | β | β | β | β |
Task | β | β | β | β | β |
Type | Note | Supported |
---|---|---|
String | - | β |
Boolean | - | β |
Long | - | β |
Int | - | β |
Enum | Use Java String converted | β |
Date | Use Java 8 dates with toString formatter | β |
Basic SDK client configuration
// All basic types are supported
class MyCustomCompanyProperties(
val name: String,
val age: Int,
val email: String,
val newsletter: Boolean,
// You can customize final property name send to HubSpot API
@JsonProperty("billing_bank_iban")
val iban: String? = null
)
val client = Client(
apiBasePath = "https://api.hubapi.com",
// Found in HubSpot company management -> Integrations -> API Keys -> Active API Key
apiKey = "xxx"
)
val companyRequest = CompanyRequest(
properties = MyCustomCompanyProperties(
name = "John Doe",
age = 34,
email = "[email protected]",
newsletter = true
)
)
val companyResponse = companiesClient.createCompany(companyRequest)
println(companyResponse.id) // HubSpot company ID
println(companyResponse.properties["name"]) // John Doe
val companyRequest = CompanyRequest(
properties = MyCustomCompanyProperties(
name = "John Doe",
age = 34,
email = "[email protected]",
newsletter = true
)
)
val companyResponse = companiesClient.changeCompany(123456789, companyRequest)
println(companyResponse.id) // HubSpot company ID
println(companyResponse.properties["name"]) // John Doe
val request = CustomObjectRequest(
properties = MySuperEventProperties(
name = "Party #2022",
address = "New York",
// Date must be formatted as "YYYY-MM-DD"
dateFrom = LocalDate
.now()
.plusDays(10)
.format(DateTimeFormatter.ISO_LOCAL_DATE),
dateUntil = LocalDate
.now()
.plusDays(15)
.format(DateTimeFormatter.ISO_LOCAL_DATE),
)
)
// HubSpot client and name of custom object table
val myEventsClient = CustomObjectClient(client, "events")
val response = myEventsClient.createCustomObjectRecord(request)
println(response.id) // HubSpot ID
println(response.properties["name"]) // Party #2022
val associationClient = AssociationClient(hubspotClient)
val associationRequest = AssociationRequest(
fromObjectType = CONTACT, // contact, company, deal, etc
fromObjectId = 1, // HubSpot ID of the contact
toObjectType = COMPANY, // contact, company, deal, etc
toObjectId = 2 // HubSpot ID of the company
)
val associationResponse = associationClient.createDefaultAssociation(associationRequest)
println(associationResponse.id)