-
Notifications
You must be signed in to change notification settings - Fork 6
/
hubspot.go
83 lines (60 loc) · 1.98 KB
/
hubspot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Package hubspot is a SDK client library for HubSpot's API
Example usage:
package main
import "github.com/leonelquinteros/hubspot"
func main() {
// Create client object with config from environment variables (HUBSPOT_API_HOST, HUBSPOT_API_KEY, HUBSPOT_OAUTH_TOKEN)
c := hubspot.NewClient(hubspot.NewClientConfig())
// Create new contact
data := hubspot.ContactsRequest{
hubspot.Properties: []hubspot.Property{
hubspot.Property{
Property: "email",
Value: "[email protected]",
},
hubspot.Property{
Property: "firstname",
Value: "Contact",
},
hubspot.Property{
Property: "lastname",
Value: "Example",
},
},
}
r, err := c.Contacts().Create(data)
if err != nil {
log.Fatal(err)
}
// Get contact by email
contact, err = c.Contacts().GetByEmail("[email protected]")
if err != nil {
log.Fatal(err)
}
// Print contact object
fmt.Printf("%+v", contact)
}
Configuration
Package can be configured using environment variables for default initialization.
When calling
hubspot.NewClientConfig()
the configuration object will be populated with information from environment variables as follow:
HUBSPOT_API_HOST
The HubSpot's API endpoint host (including schema and host), defaults to "https://api.hubapi.com" when omitted.
HUBSPOT_API_KEY
HubSpot's API secret key used to authenticate further requests. It will be preferred if both auth methods (API key and OAuth token) are present.
HUBSPOT_OAUTH_TOKEN
If HUBSPOT_API_KEY isn't present, further requests will be authenticated using this token.
Manual/eventual configuration can be set by creating a configuration object directly and pass it to the NewClient() method:
hubspot.NewClient(hubspot.ClientConfig{
APIHost: "https://api.hubspot.local"
APIKey: "vroho487hfo48hfo48y3bai38gi2"
})
*/
package hubspot
// ErrorResponse object
type ErrorResponse struct {
Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
}