github.com/schmorrison/Zoho@v1.1.4/bookings/appointment.go (about) 1 package bookings 2 3 import ( 4 "fmt" 5 6 zoho "github.com/schmorrison/Zoho" 7 ) 8 9 func (c *API) GetAppointment(bookingID zoho.Parameter) (data AppointmentResponse, err error) { 10 endpoint := zoho.Endpoint{ 11 Name: GetAppointmentModule, 12 URL: fmt.Sprintf( 13 "https://www.zohoapis.%s/bookings/v1/json/%s", 14 c.ZohoTLD, 15 GetAppointmentModule, 16 ), 17 Method: zoho.HTTPGet, 18 ResponseData: &AppointmentResponse{}, 19 URLParameters: map[string]zoho.Parameter{ 20 "filter_by": "", 21 }, 22 } 23 if bookingID == "" { 24 return AppointmentResponse{}, fmt.Errorf( 25 "Failed to get appointment due to non-availability of booking_id", 26 ) 27 } 28 endpoint.URLParameters["booking_id"] = bookingID 29 30 err = c.Zoho.HTTPRequest(&endpoint) 31 if err != nil { 32 return AppointmentResponse{}, fmt.Errorf("Failed to retrieve appointments: %s", err) 33 } 34 if v, ok := endpoint.ResponseData.(*AppointmentResponse); ok { 35 return *v, nil 36 } 37 return AppointmentResponse{}, fmt.Errorf("Data retrieved was not 'AppointmentResponse'") 38 } 39 40 func (c *API) BookAppointment(request BookAppointmentData) (data AppointmentResponse, err error) { 41 endpoint := zoho.Endpoint{ 42 Name: BookAppointmentModule, 43 URL: fmt.Sprintf( 44 "https://www.zohoapis.%s/bookings/v1/json/%s", 45 c.ZohoTLD, 46 BookAppointmentModule, 47 ), 48 Method: zoho.HTTPPost, 49 ResponseData: &AppointmentResponse{}, 50 RequestBody: request, 51 BodyFormat: zoho.URL, 52 } 53 54 err = c.Zoho.HTTPRequest(&endpoint) 55 if err != nil { 56 return AppointmentResponse{}, fmt.Errorf("Failed to book appointment: %s", err) 57 } 58 if v, ok := endpoint.ResponseData.(*AppointmentResponse); ok { 59 60 return *v, nil 61 } 62 return AppointmentResponse{}, fmt.Errorf("Data retrieved was not 'AppointmentResponse'") 63 } 64 65 func (c *API) UpdateAppointment( 66 request UpdateAppointmentData, 67 ) (data AppointmentResponse, err error) { 68 endpoint := zoho.Endpoint{ 69 Name: UpdateAppointmentModule, 70 URL: fmt.Sprintf( 71 "https://www.zohoapis.%s/bookings/v1/json/%s", 72 c.ZohoTLD, 73 UpdateAppointmentModule, 74 ), 75 Method: zoho.HTTPPost, 76 ResponseData: &AppointmentResponse{}, 77 RequestBody: request, 78 BodyFormat: zoho.URL, 79 } 80 81 err = c.Zoho.HTTPRequest(&endpoint) 82 if err != nil { 83 return AppointmentResponse{}, fmt.Errorf("Failed to update appointments: %s", err) 84 } 85 if v, ok := endpoint.ResponseData.(*AppointmentResponse); ok { 86 87 return *v, nil 88 } 89 return AppointmentResponse{}, fmt.Errorf("Data retrieved was not 'AppointmentResponse'") 90 } 91 92 func (c *API) RescheduleAppointment( 93 request RescheduleAppointmentData, 94 ) (data AppointmentResponse, err error) { 95 endpoint := zoho.Endpoint{ 96 Name: RescheduleAppointmentModule, 97 URL: fmt.Sprintf( 98 "https://www.zohoapis.%s/bookings/v1/json/%s", 99 c.ZohoTLD, 100 RescheduleAppointmentModule, 101 ), 102 Method: zoho.HTTPPost, 103 ResponseData: &AppointmentResponse{}, 104 RequestBody: request, 105 BodyFormat: zoho.URL, 106 } 107 108 err = c.Zoho.HTTPRequest(&endpoint) 109 if err != nil { 110 return AppointmentResponse{}, fmt.Errorf("Failed to update appointments: %s", err) 111 } 112 if v, ok := endpoint.ResponseData.(*AppointmentResponse); ok { 113 114 return *v, nil 115 } 116 return AppointmentResponse{}, fmt.Errorf("Data retrieved was not 'AppointmentResponse'") 117 } 118 119 type UpdateAppointmentData struct { 120 BookingID string `url:"booking_id"` 121 Action string `url:"action"` 122 } 123 124 type RescheduleAppointmentData struct { 125 BookingID string `url:"booking_id"` 126 StaffId string `url:"staff_id,omitempty"` 127 StartTime string `url:"start_time,omitempty"` 128 } 129 130 type CustomerDetails struct { 131 Name string `json:"name"` 132 Email string `json:"email"` 133 PhoneNumber string `json:"phone_number"` 134 } 135 136 type BookAppointmentData struct { 137 ServiceId string `url:"service_id"` 138 StaffId string `url:"staff_id,omitempty"` 139 ResourceId string `url:"resource_id,omitempty"` 140 FromTime string `url:"from_time"` 141 TimeZone string `url:"time_zone,omitempty"` 142 Customer_Details CustomerDetails `url:"customer_details,json,omitempty"` // Note the option `json` before `omitempty`, the order shouldn't matter 143 } 144 145 //AppointmentResponse is the data returned by GetAppointment 146 type AppointmentResponse struct { 147 Response struct { 148 ErrorMessage string `json:"errormessage,omitempty"` 149 Status string `json:"status"` 150 LogMessage []string `json:"logMessage"` 151 ReturnValue struct { 152 StaffName string `json:"staff_name"` 153 CustomerMoreInfo struct{} `json:"customer_more_info"` 154 CustomerBookingStartTime string `json:"customer_booking_start_time"` 155 CustomerContactNo string `json:"customer_contact_no"` 156 BookedOn string `json:"booked_on"` 157 BookingID string `json:"booking_id"` 158 WorkspaceId string `json:"workspace_id"` 159 Duration string `json:"duration"` 160 ServiceId string `json:"service_id"` 161 StaffId string `json:"staff_id"` 162 CostPaid string `json:"cost_paid"` 163 Currency string `json:"currency"` 164 WorkspaceName string `json:"workspace_name"` 165 Cost string `json:"cost"` 166 ServiceName string `json:"service_name"` 167 TimeZone string `json:"time_zone"` 168 StartTime string `json:"start_time"` 169 Due string `json:"due"` 170 CustomerEmail string `json:"customer_email"` 171 BookingType string `json:"booking_type"` 172 CustomerName string `json:"customer_name"` 173 SummaryUrl string `json:"summary_url"` 174 CustomerBookingTimeZone string `json:"customer_booking_time_zone"` 175 Status string `json:status"` 176 } `json:"returnvalue"` 177 } `json:"response"` 178 }