github.com/schmorrison/Zoho@v1.1.4/invoice/list_contact_persons.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/#Contact_Persons_List_contact_persons
    10  //func (c *API) ListContactPersons(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data ListContactPersonsResponse, err error) {
    11  func (c *API) ListContactPersons() (data ListContactPersonsResponse, err error) {
    12  
    13  	endpoint := zoho.Endpoint{
    14  		Name: ContactsModule,
    15  		URL: fmt.Sprintf(
    16  			"https://invoice.zoho.%s/api/v3/%s/%s",
    17  			c.ZohoTLD,
    18  			ContactsModule,
    19  			ContactsPersonSubModule,
    20  		),
    21  		Method:       zoho.HTTPGet,
    22  		ResponseData: &ListContactPersonsResponse{},
    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  	err = c.Zoho.HTTPRequest(&endpoint)
    37  	if err != nil {
    38  		return ListContactPersonsResponse{}, fmt.Errorf(
    39  			"Failed to retrieve expense reports: %s",
    40  			err,
    41  		)
    42  	}
    43  
    44  	if v, ok := endpoint.ResponseData.(*ListContactPersonsResponse); ok {
    45  		// Check if the request succeeded
    46  		if v.Code != 0 {
    47  			return *v, fmt.Errorf("Failed to list contact persons: %s", v.Message)
    48  		}
    49  		return *v, nil
    50  	}
    51  	return ListContactPersonsResponse{}, fmt.Errorf(
    52  		"Data retrieved was not 'ListContactPersonsResponse'",
    53  	)
    54  }
    55  
    56  type ListContactPersonsResponse struct {
    57  	Code           int    `json:"code"`
    58  	Message        string `json:"message"`
    59  	ContactPersons []struct {
    60  		ContactID        string `json:"contact_id"`
    61  		ContactPersonID  string `json:"contact_person_id"`
    62  		Salutation       string `json:"salutation"`
    63  		FirstName        string `json:"first_name"`
    64  		LastName         string `json:"last_name"`
    65  		Email            string `json:"email"`
    66  		Phone            string `json:"phone,omitempty"`
    67  		Mobile           string `json:"mobile,omitempty"`
    68  		IsPrimaryContact bool   `json:"is_primary_contact"`
    69  		Skype            string `json:"skype,omitempty"`
    70  		Designation      string `json:"designation,omitempty"`
    71  		Department       string `json:"department,omitempty"`
    72  		IsAddedInPortal  bool   `json:"is_added_in_portal"`
    73  	} `json:"contact_persons"`
    74  }