/hubspot

HubSpot API in Golang

Primary LanguageGoMIT LicenseMIT

HubSpot

HubSpot API in Go.

Installation

go get github.com/Fyb3roptik/hubspot

Examples

import(
  "github.com/Fyb3roptik/hubspot"
)

api_key := os.Getenv("HUBSPOT_API_KEY")

Create Contact via Contact API

a := hubspot.NewContact(api_key, "abhi@acksin.com")
a.Add("firstname", "Abhi")
a.Add("lastname", "Yerra")
a.Add("company", "Acksin")
a.Add("lifecyclestage", "opportunity")
a.Add("acksinsoftware", "opsZero")
resp := a.Publish()
if resp.Vid != 901 {
        t.Errorf("Failed to update contact")
}

Create New Deal via Deal API

d := hubspot.NewDeal(api_key)
d.Associations.AssociatedVids = []int{resp.Vid}
d.Add("dealname", "Tim's Newer Deal")
d.Add("dealstage", "closedwon")
d.Add("closedate", Timestamp())
d.Add("amount", "60000")
d.Add("dealtype", "newbusiness")
d.Publish()

Create Single-Send Email via Single-Send API

// Single Send Email has 2 property types. Contact and Custom, so we need to specify using the first param. The To, From and ReplyTo are required.
message := hubspot.Message{
  To: "someuser@mail.com",
  From: "noreply@yourdomain.com",
  ReplyTo: "noreply@yourdomain.com",
}
e := hubspot.NewEmail(api_key, email_id, message)

// Adding a contact property
e.Add("contact", "firstname", "Jack")

// Adding a custom property
e.Add("custom", "some_custom_key", "some_custom_value")

e.Publish()

Create a New Contact via Form API

e := hubspot.NewForm(api_key, portal_id, form_guid)
e.Add("firstname", "Tester")
e.Add("lastname", "McTest")
e.Add("email", "tester@testing.com")
e.Publish()

Credit

This is based on the original library written by acksin