-
Notifications
You must be signed in to change notification settings - Fork 34
/
get_contact.go
99 lines (91 loc) · 4.02 KB
/
get_contact.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package invoice
import (
"fmt"
zoho "github.com/schmorrison/Zoho"
)
//https://www.zoho.com/invoice/api/v3/#Contacts_Get_a_Contact
//func (c *API) GetContact(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data GetContactResponse, err error) {
func (c *API) GetContact(contactId string) (data GetContactResponse, err error) {
endpoint := zoho.Endpoint{
Name: InvoicesModule,
URL: fmt.Sprintf(
"https://invoice.zoho.%s/api/v3/%s/%s",
c.ZohoTLD,
ContactsModule,
contactId,
),
Method: zoho.HTTPGet,
ResponseData: &GetContactResponse{},
URLParameters: map[string]zoho.Parameter{
"filter_by": "",
},
BodyFormat: zoho.JSON_STRING,
Headers: map[string]string{
InvoiceAPIEndpointHeader: c.OrganizationID,
},
}
/*for k, v := range params {
endpoint.URLParameters[k] = v
}
*/
err = c.Zoho.HTTPRequest(&endpoint)
if err != nil {
return GetContactResponse{}, fmt.Errorf("Failed to retrieve contact: %s", err)
}
if v, ok := endpoint.ResponseData.(*GetContactResponse); ok {
// Check if the request succeeded
if v.Code != 0 {
return *v, fmt.Errorf("Failed to retrieve contact: %s", v.Message)
}
return *v, nil
}
return GetContactResponse{}, fmt.Errorf("Data retrieved was not 'GetContactResponse'")
}
type GetContactResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Contact struct {
ContactID string `json:"contact_id"`
ContactName string `json:"contact_name"`
CompanyName string `json:"company_name"`
HasTransaction bool `json:"has_transaction"`
ContactType string `json:"contact_type"`
IsTaxable bool `json:"is_taxable"`
TaxID string `json:"tax_id"`
TaxName string `json:"tax_name"`
TaxPercentage float64 `json:"tax_percentage"`
TaxAuthorityID string `json:"tax_authority_id"`
TaxExemptionID string `json:"tax_exemption_id"`
GSTNo string `json:"gst_no"`
GSTTreatment string `json:"gst_treatment"`
IsLinkedWithZohocrm bool `json:"is_linked_with_zohocrm"`
Website string `json:"website"`
PrimaryContactID string `json:"primary_contact_id"`
PaymentTerms int64 `json:"payment_terms"`
PaymentTermsLabel string `json:"payment_terms_label"`
CurrencyID string `json:"currency_id"`
CurrencyCode string `json:"currency_code"`
CurrencySymbol string `json:"currency_symbol"`
LanguageCode string `json:"language_code"`
OutstandingReceivableAmount float64 `json:"outstanding_receivable_amount"`
OutstandingReceivableAmountBcy float64 `json:"outstanding_receivable_amount_bcy"`
UnusedCreditsReceivableAmount float64 `json:"unused_credits_receivable_amount"`
UnusedCreditsReceivableAmountBcy float64 `json:"unused_credits_receivable_amount_bcy"`
Status string `json:"status"`
Facebook string `json:"facebook"`
Twitter string `json:"twitter"`
PaymentReminderEnabled bool `json:"payment_reminder_enabled"`
CustomFields []struct {
Value string `json:"value"`
Index int64 `json:"index"`
Label string `json:"label"`
} `json:"custom_fields"`
BillingAddress ContactAddress `json:"billing_address"`
ShippingAddress ContactAddress `json:"shipping_address"`
ContactPersons []ContactPerson `json:"contact_persons"`
DefaultTemplates ContactDefaultTemplates `json:"default_templates"`
Notes string `json:"notes"`
CreatedTime string `json:"created_time"`
LastModifiedTime string `json:"last_modified_time"`
} `json:"contact"`
}