github.com/schmorrison/Zoho@v1.1.4/invoice/update_contact.go (about) 1 package invoice 2 3 import ( 4 "fmt" 5 6 zoho "github.com/schmorrison/Zoho" 7 ) 8 9 //https://www.zoho.com/invoice/api/v3/#Contacts_Update_a_Contact 10 //func (c *API) UpdateContact(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data UpdateContactResponse, err error) { 11 func (c *API) UpdateContact( 12 request interface{}, 13 contactId string, 14 ) (data UpdateContactResponse, err error) { 15 16 endpoint := zoho.Endpoint{ 17 Name: ContactsModule, 18 URL: fmt.Sprintf( 19 "https://invoice.zoho.%s/api/v3/%s/%s", 20 c.ZohoTLD, 21 ContactsModule, 22 contactId, 23 ), 24 Method: zoho.HTTPPut, 25 ResponseData: &UpdateContactResponse{}, 26 URLParameters: map[string]zoho.Parameter{ 27 "filter_by": "", 28 }, 29 RequestBody: &request, 30 BodyFormat: zoho.JSON_STRING, 31 Headers: map[string]string{ 32 InvoiceAPIEndpointHeader: c.OrganizationID, 33 }, 34 } 35 36 /*for k, v := range params { 37 endpoint.URLParameters[k] = v 38 }*/ 39 40 err = c.Zoho.HTTPRequest(&endpoint) 41 if err != nil { 42 return UpdateContactResponse{}, fmt.Errorf("Failed to create contact: %s", err) 43 } 44 45 if v, ok := endpoint.ResponseData.(*UpdateContactResponse); ok { 46 // Check if the request succeeded 47 if v.Code != 0 { 48 return *v, fmt.Errorf("Failed to update contact: %s", v.Message) 49 } 50 return *v, nil 51 } 52 return UpdateContactResponse{}, fmt.Errorf("Data retrieved was not 'UpdateContactResponse'") 53 } 54 55 type UpdateContactRequest struct { 56 ContactName string `json:"contact_name,omitempty"` 57 CompanyName string `json:"company_name,omitempty"` 58 CustomerSubType string `json:"customer_sub_type,omitempty"` 59 PaymentTerms int64 `json:"payment_terms,omitempty"` 60 CurrencyID string `json:"currency_id,omitempty"` 61 Website string `json:"website,omitempty"` 62 CustomFields []CustomFieldRequest `json:"custom_fields,omitempty"` 63 BillingAddress ContactAddress `json:"billing_address,omitempty"` 64 ShippingAddress ContactAddress `json:"shipping_address,omitempty"` 65 ContactPersons []ContactPerson `json:"contact_persons,omitempty"` 66 DefaultTemplates ContactDefaultTemplates `json:"default_templates,omitempty"` 67 LanguageCode string `json:"language_code,omitempty"` 68 Notes string `json:"notes,omitempty"` 69 PlaceOfContact string `json:"place_of_contact,omitempty"` 70 GSTNo string `json:"gst_no,omitempty"` 71 GSTTreatment string `json:"gst_treatment,omitempty"` 72 TaxExemptionID string `json:"tax_exemption_id,omitempty"` 73 TaxAuthorityID string `json:"tax_authority_id,omitempty"` 74 TaxID string `json:"tax_id,omitempty"` 75 IsTaxable string `json:"is_taxable,omitempty"` 76 Facebook string `json:"facebook,omitempty"` 77 Twitter string `json:"twitter,omitempty"` 78 } 79 80 type UpdateContactResponse struct { 81 Code int `json:"code"` 82 Message string `json:"message"` 83 Contact struct { 84 ContactID string `json:"contact_id"` 85 ContactName string `json:"contact_name"` 86 CompanyName string `json:"company_name"` 87 HasTransaction bool `json:"has_transaction"` 88 ContactType string `json:"contact_type"` 89 IsTaxable bool `json:"is_taxable"` 90 TaxID string `json:"tax_id"` 91 TaxName string `json:"tax_name"` 92 TaxPercentage float64 `json:"tax_percentage"` 93 TaxExemptionID string `json:"tax_exemption_id"` 94 TaxAuthorityID string `json:"tax_authority_id"` 95 GSTNo string `json:"gst_no"` 96 GSTTreatment string `json:"gst_treatment"` 97 IsLinkedWithZohocrm bool `json:"is_linked_with_zohocrm"` 98 Website string `json:"website"` 99 PrimaryContactID string `json:"primary_contact_id"` 100 PaymentTerms int64 `json:"payment_terms"` 101 PaymentTermsLabel string `json:"payment_terms_label"` 102 CurrencyID string `json:"currency_id"` 103 CurrencyCode string `json:"currency_code"` 104 CurrencySymbol string `json:"currency_symbol"` 105 LanguageCode string `json:"language_code"` 106 OutstandingReceivableAmount float64 `json:"outstanding_receivable_amount"` 107 OutstandingReceivableAmountBcy float64 `json:"outstanding_receivable_amount_bcy"` 108 UnusedCreditsReceivableAmount float64 `json:"unused_credits_receivable_amount"` 109 UnusedCreditsReceivableAmountBcy float64 `json:"unused_credits_receivable_amount_bcy"` 110 Status string `json:"status"` 111 PaymentReminderEnabled bool `json:"payment_reminder_enabled"` 112 CustomFields []struct { 113 Value string `json:"value"` 114 Index int64 `json:"index"` 115 Label string `json:"label"` 116 } `json:"custom_fields"` 117 BillingAddress ContactAddress `json:"billing_address"` 118 ShippingAddress ContactAddress `json:"shipping_address"` 119 Facebook string `json:"facebook"` 120 Twitter string `json:"twitter"` 121 ContactPersons []ContactPerson `json:"contact_persons"` 122 DefaultTemplates ContactDefaultTemplates `json:"default_templates"` 123 Notes string `json:"notes"` 124 CreatedTime string `json:"created_time"` 125 LastModifiedTime string `json:"last_modified_time"` 126 } 127 }