github.com/schmorrison/Zoho@v1.1.4/invoice/get_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_Get_a_Contact
    10  //func (c *API) GetContact(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data GetContactResponse, err error) {
    11  func (c *API) GetContact(contactId string) (data GetContactResponse, err error) {
    12  
    13  	endpoint := zoho.Endpoint{
    14  		Name: InvoicesModule,
    15  		URL: fmt.Sprintf(
    16  			"https://invoice.zoho.%s/api/v3/%s/%s",
    17  			c.ZohoTLD,
    18  			ContactsModule,
    19  			contactId,
    20  		),
    21  		Method:       zoho.HTTPGet,
    22  		ResponseData: &GetContactResponse{},
    23  		URLParameters: map[string]zoho.Parameter{
    24  			"filter_by": "",
    25  		},
    26  		BodyFormat: zoho.JSON_STRING,
    27  		Headers: map[string]string{
    28  			InvoiceAPIEndpointHeader: c.OrganizationID,
    29  		},
    30  	}
    31  
    32  	/*for k, v := range params {
    33  	  	endpoint.URLParameters[k] = v
    34  	  }
    35  	*/
    36  
    37  	err = c.Zoho.HTTPRequest(&endpoint)
    38  	if err != nil {
    39  		return GetContactResponse{}, fmt.Errorf("Failed to retrieve contact: %s", err)
    40  	}
    41  
    42  	if v, ok := endpoint.ResponseData.(*GetContactResponse); ok {
    43  		// Check if the request succeeded
    44  		if v.Code != 0 {
    45  			return *v, fmt.Errorf("Failed to retrieve contact: %s", v.Message)
    46  		}
    47  		return *v, nil
    48  	}
    49  	return GetContactResponse{}, fmt.Errorf("Data retrieved was not 'GetContactResponse'")
    50  }
    51  
    52  type GetContactResponse struct {
    53  	Code    int    `json:"code"`
    54  	Message string `json:"message"`
    55  	Contact struct {
    56  		ContactID                        string  `json:"contact_id"`
    57  		ContactName                      string  `json:"contact_name"`
    58  		CompanyName                      string  `json:"company_name"`
    59  		HasTransaction                   bool    `json:"has_transaction"`
    60  		ContactType                      string  `json:"contact_type"`
    61  		IsTaxable                        bool    `json:"is_taxable"`
    62  		TaxID                            string  `json:"tax_id"`
    63  		TaxName                          string  `json:"tax_name"`
    64  		TaxPercentage                    float64 `json:"tax_percentage"`
    65  		TaxAuthorityID                   string  `json:"tax_authority_id"`
    66  		TaxExemptionID                   string  `json:"tax_exemption_id"`
    67  		GSTNo                            string  `json:"gst_no"`
    68  		GSTTreatment                     string  `json:"gst_treatment"`
    69  		IsLinkedWithZohocrm              bool    `json:"is_linked_with_zohocrm"`
    70  		Website                          string  `json:"website"`
    71  		PrimaryContactID                 string  `json:"primary_contact_id"`
    72  		PaymentTerms                     int64   `json:"payment_terms"`
    73  		PaymentTermsLabel                string  `json:"payment_terms_label"`
    74  		CurrencyID                       string  `json:"currency_id"`
    75  		CurrencyCode                     string  `json:"currency_code"`
    76  		CurrencySymbol                   string  `json:"currency_symbol"`
    77  		LanguageCode                     string  `json:"language_code"`
    78  		OutstandingReceivableAmount      float64 `json:"outstanding_receivable_amount"`
    79  		OutstandingReceivableAmountBcy   float64 `json:"outstanding_receivable_amount_bcy"`
    80  		UnusedCreditsReceivableAmount    float64 `json:"unused_credits_receivable_amount"`
    81  		UnusedCreditsReceivableAmountBcy float64 `json:"unused_credits_receivable_amount_bcy"`
    82  		Status                           string  `json:"status"`
    83  		Facebook                         string  `json:"facebook"`
    84  		Twitter                          string  `json:"twitter"`
    85  		PaymentReminderEnabled           bool    `json:"payment_reminder_enabled"`
    86  		CustomFields                     []struct {
    87  			Value string `json:"value"`
    88  			Index int64  `json:"index"`
    89  			Label string `json:"label"`
    90  		} `json:"custom_fields"`
    91  		BillingAddress   ContactAddress          `json:"billing_address"`
    92  		ShippingAddress  ContactAddress          `json:"shipping_address"`
    93  		ContactPersons   []ContactPerson         `json:"contact_persons"`
    94  		DefaultTemplates ContactDefaultTemplates `json:"default_templates"`
    95  		Notes            string                  `json:"notes"`
    96  		CreatedTime      string                  `json:"created_time"`
    97  		LastModifiedTime string                  `json:"last_modified_time"`
    98  	} `json:"contact"`
    99  }