github.com/schmorrison/Zoho@v1.1.4/invoice/create_contact_person.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_Create_a_contact_person
    10  //func (c *API) CreateContactPerson(request interface{}, OrganizationID string, params map[string]zoho.Parameter) (data CreateContactPersonResponse, err error) {
    11  func (c *API) CreateContactPerson(
    12  	request interface{},
    13  ) (data CreateContactPersonResponse, err error) {
    14  
    15  	endpoint := zoho.Endpoint{
    16  		Name: ContactsModule,
    17  		URL: fmt.Sprintf(
    18  			"https://invoice.zoho.%s/api/v3/%s/%s",
    19  			c.ZohoTLD,
    20  			ContactsModule,
    21  			ContactsPersonSubModule,
    22  		),
    23  		Method:       zoho.HTTPPost,
    24  		ResponseData: &CreateContactPersonResponse{},
    25  		URLParameters: map[string]zoho.Parameter{
    26  			"filter_by": "",
    27  		},
    28  		RequestBody: &request,
    29  		BodyFormat:  zoho.JSON_STRING,
    30  		Headers: map[string]string{
    31  			InvoiceAPIEndpointHeader: c.OrganizationID,
    32  		},
    33  	}
    34  
    35  	/*for k, v := range params {
    36  		endpoint.URLParameters[k] = v
    37  	}*/
    38  
    39  	err = c.Zoho.HTTPRequest(&endpoint)
    40  	if err != nil {
    41  		return CreateContactPersonResponse{}, fmt.Errorf("Failed to create contact person: %s", err)
    42  	}
    43  
    44  	if v, ok := endpoint.ResponseData.(*CreateContactPersonResponse); ok {
    45  		// Do not test this endpoint code return against 0 as it may succeed with warnings
    46  		/* Check if the request succeeded
    47  		if v.Code != 0 {
    48  			return *v, fmt.Errorf("Failed to create contact person: %s", v.Message)
    49  		}*/
    50  		return *v, nil
    51  	}
    52  	return CreateContactPersonResponse{}, fmt.Errorf(
    53  		"Data retrieved was not 'CreateContactPersonResponse'",
    54  	)
    55  }
    56  
    57  type CreateContactPersonRequest struct {
    58  	ContactID    string `json:"contact_id"`
    59  	Salutation   string `json:"salutation,omitempty"`
    60  	FirstName    string `json:"first_name"`
    61  	LastName     string `json:"last_name"`
    62  	Email        string `json:"email"`
    63  	Phone        string `json:"phone,omitempty"`
    64  	Mobile       string `json:"mobile,omitempty"`
    65  	Skype        string `json:"skype,omitempty"`
    66  	Designation  string `json:"designation,omitempty"`
    67  	Department   string `json:"department,omitempty"`
    68  	EnablePortal bool   `json:"enable_portal"`
    69  }
    70  
    71  type CreateContactPersonResponse struct {
    72  	Code          int    `json:"code"`
    73  	Message       string `json:"message"`
    74  	ContactPerson struct {
    75  		ContactID        string `json:"contact_id"`
    76  		ContactPersonID  string `json:"contact_person_id"`
    77  		Salutation       string `json:"salutation"`
    78  		FirstName        string `json:"first_name"`
    79  		LastName         string `json:"last_name"`
    80  		Email            string `json:"email"`
    81  		Phone            string `json:"phone,omitempty"`
    82  		Mobile           string `json:"mobile,omitempty"`
    83  		IsPrimaryContact bool   `json:"is_primary_contact"`
    84  		Skype            string `json:"skype,omitempty"`
    85  		Designation      string `json:"designation,omitempty"`
    86  		Department       string `json:"department,omitempty"`
    87  		IsAddedInPortal  bool   `json:"is_added_in_portal"`
    88  	} `json:"contact_person"`
    89  }