Skip to content

Latest commit

 

History

History
141 lines (106 loc) · 4.04 KB

README.md

File metadata and controls

141 lines (106 loc) · 4.04 KB

🤖 HubSpot Kotlin SDK

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

Supported features

Feature List Read Create Change Delete
Company
Custom objects
Deal
Contact
Associations
Task

Supported types

Type Note Supported
String -
Boolean -
Long -
Int -
Enum Use Java String converted
Date Use Java 8 dates with toString formatter

Usage Examples

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"
)

#️⃣ Company entity

Create brand-new company

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

Change existing company

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

#️⃣ Custom objects

Create brand-new custom object record

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

Associate a contact to an existing company with default label

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)