package main import ( "encoding/json" "fmt" "log/slog" ) type APIResponser interface { CheckDecodedResponse() error } // General API Response type. All API responses will have // A result field and if it's not success a message field type APIResponse struct { Result string `json:"result"` Message string `json:"message,omitempty"` } func (r APIResponse) CheckDecodedResponse() error { if r.Result != "success" { slog.Error("Upstream server error", "message", r.Message) return fmt.Errorf("Got error from upstream: %v", r.Message) } return nil } // API GetTickets // https://developers.whmcs.com/api-reference/gettickets/ type GetTicketsResponse struct { APIResponse Tickets struct { Ticket []GetTicketsTicket `json:"ticket"` } `json:"tickets"` } type GetTicketsTicket struct { Id int `json:"id"` Tid string `json:"tid"` Deptid int `json:"deptid,omitempty"` Userid int `json:"userid,omitempty"` Name string `json:"name,omitempty"` Owner_name string `json:"owner_name,omitempty"` Email string `json:"email,omitempty"` Requestor_name string `json:"requestor_name,omitempty"` Requestor_email string `json:"requestor_email,omitempty"` Requestor_type string `json:"requestor_type,omitempty"` Cc string `json:"cc,omitempty"` C string `json:"c,omitempty"` Date string `json:"date,omitempty"` Subject string `json:"subject,omitempty"` Status string `json:"status,omitempty"` Priority string `json:"priority,omitempty"` Admin string `json:"admin,omitempty"` Lastreply string `json:"lastreply,omitempty"` Flag int `json:"flag,omitempty"` Service string `json:"service,omitempty"` } // API GetTicket // https://developers.whmcs.com/api-reference/getticket/ type GetTicketNote struct { Noteid int `json:"noteid"` Date string `json:"date,omitempty"` Message string `json:"message,omitempty"` Admin string `json:"admin,omitempty"` } type GetTicketReply struct { Replyid json.Number `json:"replyid"` Userid int `json:"userid"` Contactid int `json:"contactid,omitempty"` Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` Requestor_name string `json:"requestor_name,omitempty"` Requestor_email string `json:"requestor_email,omitempty"` Requestor_type string `json:"requestor_type,omitempty"` Date string `json:"date,omitempty"` Message string `json:"message,omitempty"` Admin string `json:"admin,omitempty"` Rating json.Number `json:"rating,omitempty"` } type GetTicketResponse struct { APIResponse Ticketid int `json:"ticketid"` Tid string `json:"tid,omitempty"` C string `json:"c,omitempty"` Deptid int `json:"deptid,omitempty"` Deptname string `json:"deptname,omitempty"` Userid int `json:"userid,omitempty"` Contactid int `json:"contactid,omitempty"` Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` Requestor_name string `json:"requestor_name,omitempty"` Requestor_type string `json:"requestor_type,omitempty"` Requestor_email string `json:"requestor_email,omitempty"` Cc string `json:"cc,omitempty"` Date string `json:"date,omitempty"` Subject string `json:"subject,omitempty"` Status string `json:"status,omitempty"` Priority string `json:"priority,omitempty"` Admin string `json:"admin,omitempty"` Lastreply string `json:"lastreply,omitempty"` Flag int `json:"flag,omitempty"` Service string `json:"service,omitempty"` Replies struct { Reply []GetTicketReply `json:"reply"` } `json:"replies"` Notes []any `json:"notes,omitempty"` }