github.com/schmorrison/Zoho@v1.1.4/invoice/list_contacts.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_List_Contacts
    10  //func (c *API) ListContacts(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data ListContactsResponse, err error) {
    11  func (c *API) ListContacts() (data ListContactsResponse, err error) {
    12  
    13  	endpoint := zoho.Endpoint{
    14  		Name:         ContactsModule,
    15  		URL:          fmt.Sprintf("https://invoice.zoho.%s/api/v3/%s", c.ZohoTLD, ContactsModule),
    16  		Method:       zoho.HTTPGet,
    17  		ResponseData: &ListContactsResponse{},
    18  		URLParameters: map[string]zoho.Parameter{
    19  			"filter_by": "",
    20  		},
    21  		BodyFormat: zoho.JSON_STRING,
    22  		Headers: map[string]string{
    23  			InvoiceAPIEndpointHeader: c.OrganizationID,
    24  		},
    25  	}
    26  
    27  	/*for k, v := range params {
    28  		endpoint.URLParameters[k] = v
    29  	}
    30  	*/
    31  
    32  	err = c.Zoho.HTTPRequest(&endpoint)
    33  	if err != nil {
    34  		return ListContactsResponse{}, fmt.Errorf("Failed to retrieve expense reports: %s", err)
    35  	}
    36  
    37  	if v, ok := endpoint.ResponseData.(*ListContactsResponse); ok {
    38  		// Check if the request succeeded
    39  		if v.Code != 0 {
    40  			return *v, fmt.Errorf("Failed to list contacts: %s", v.Message)
    41  		}
    42  		return *v, nil
    43  	}
    44  	return ListContactsResponse{}, fmt.Errorf("Data retrieved was not 'ListContactsResponse'")
    45  }
    46  
    47  // ListContactsResponse is the data returned by GetExpenseReports
    48  type ListContactsResponse struct {
    49  	Code     int    `json:"code"`
    50  	Message  string `json:"message"`
    51  	Contacts []struct {
    52  		ContactID                     string  `json:"contact_id"`
    53  		ContactName                   string  `json:"contact_name"`
    54  		CompanyName                   string  `json:"company_name"`
    55  		ContactType                   string  `json:"contact_type"`
    56  		Status                        string  `json:"status"`
    57  		PaymentTerms                  int64   `json:"payment_terms"`
    58  		PaymentTermsLabel             string  `json:"payment_terms_label"`
    59  		CurrencyID                    string  `json:"currency_id"`
    60  		CurrencyCode                  string  `json:"currency_code"`
    61  		OutstandingReceivableAmount   float64 `json:"outstanding_receivable_amount"`
    62  		UnusedCreditsReceivableAmount float64 `json:"unused_credits_receivable_amount"`
    63  		FirstName                     string  `json:"first_name"`
    64  		LastName                      string  `json:"last_name"`
    65  		Email                         string  `json:"email"`
    66  		Phone                         string  `json:"phone"`
    67  		Mobile                        string  `json:"mobile"`
    68  		CreatedTime                   string  `json:"created_time"`
    69  		LastModifiedTime              string  `json:"last_modified_time"`
    70  		/*CustomFields  []struct {
    71  			CustomfieldID string `json:"customfield_id"`
    72  			Label         string `json:"label"`
    73  			Value         string `json:"value"`
    74  		} `json:"custom_fields"`*/
    75  	} `json:"contacts"`
    76  }