-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.go
82 lines (67 loc) · 3.27 KB
/
contacts.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
package hubspot
import (
"context"
"io/ioutil"
"encoding/json"
"time"
)
type ContactsService service
type ContactPostResponse struct {
Status string `json:"status,omitempty"`
Message string `json:"message,omitempty"`
CorrelationID string `json:"correlationId,omitempty"`
Category string `json:"category,omitempty"`
ID string `json:"id,omitempty"`
Properties struct {
Createdate time.Time `json:"createdate,omitempty"`
Email string `json:"email,omitempty"`
Firstname string `json:"firstname,omitempty"`
HsAllContactVids string `json:"hs_all_contact_vids,omitempty"`
HsCurrentlyEnrolledInProspectingAgent string `json:"hs_currently_enrolled_in_prospecting_agent,omitempty"`
HsEmailDomain string `json:"hs_email_domain,omitempty"`
HsIsContact string `json:"hs_is_contact,omitempty"`
HsIsUnworked string `json:"hs_is_unworked,omitempty"`
HsLifecyclestageLeadDate time.Time `json:"hs_lifecyclestage_lead_date,omitempty"`
HsMarketableStatus string `json:"hs_marketable_status,omitempty"`
HsMarketableUntilRenewal string `json:"hs_marketable_until_renewal,omitempty"`
HsMembershipHasAccessedPrivateContent string `json:"hs_membership_has_accessed_private_content,omitempty"`
HsObjectID string `json:"hs_object_id,omitempty"`
HsObjectSource string `json:"hs_object_source,omitempty"`
HsObjectSourceID string `json:"hs_object_source_id,omitempty"`
HsObjectSourceLabel string `json:"hs_object_source_label,omitempty"`
HsPipeline string `json:"hs_pipeline,omitempty"`
HsRegisteredMember string `json:"hs_registered_member,omitempty"`
Lastmodifieddate time.Time `json:"lastmodifieddate,omitempty"`
Lastname string `json:"lastname,omitempty"`
Lifecyclestage string `json:"lifecyclestage,omitempty"`
} `json:"properties,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Archived bool `json:"archived,omitempty"`
}
type PostContact struct {
Properties *PostContactProperties `json:"properties,omitempty"`
}
type PostContactProperties struct {
Email string `json:"email,omitempty"`
FirstName string `json:"firstname,omitempty"`
LastName string `json:"lastname,omitempty"`
}
func (s *ContactsService) PostContact(ctx context.Context, mapping *PostContact) (ContactPostResponse, error) {
req, err := s.client.NewRequest("POST", "crm/v3/objects/contacts", mapping)
var result ContactPostResponse
if err != nil {
return result, err
}
m := new(PostContact)
resp, err := s.client.Do(ctx, req, m)
if err != nil {
return result, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) // response body is []byte
if err := json.Unmarshal(body, &result); err != nil { // Parse []byte to the go struct pointer
return result, err
}
return result, nil
}