whmcsapi_types.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log/slog"
  6. )
  7. type APIResponser interface {
  8. CheckDecodedResponse() error
  9. }
  10. // General API Response type. All API responses will have
  11. // A result field and if it's not success a message field
  12. type APIResponse struct {
  13. Result string `json:"result"`
  14. Message string `json:"message,omitempty"`
  15. }
  16. func (r APIResponse) CheckDecodedResponse() error {
  17. if r.Result != "success" {
  18. slog.Error("Upstream server error", "message", r.Message)
  19. return fmt.Errorf("Got error from upstream: %v", r.Message)
  20. }
  21. return nil
  22. }
  23. // API GetTickets
  24. // https://developers.whmcs.com/api-reference/gettickets/
  25. type GetTicketsResponse struct {
  26. APIResponse
  27. Tickets struct {
  28. Ticket []GetTicketsTicket `json:"ticket"`
  29. } `json:"tickets"`
  30. }
  31. type GetTicketsTicket struct {
  32. Id int `json:"id"`
  33. Tid string `json:"tid"`
  34. Deptid int `json:"deptid,omitempty"`
  35. Userid int `json:"userid,omitempty"`
  36. Name string `json:"name,omitempty"`
  37. Owner_name string `json:"owner_name,omitempty"`
  38. Email string `json:"email,omitempty"`
  39. Requestor_name string `json:"requestor_name,omitempty"`
  40. Requestor_email string `json:"requestor_email,omitempty"`
  41. Requestor_type string `json:"requestor_type,omitempty"`
  42. Cc string `json:"cc,omitempty"`
  43. C string `json:"c,omitempty"`
  44. Date string `json:"date,omitempty"`
  45. Subject string `json:"subject,omitempty"`
  46. Status string `json:"status,omitempty"`
  47. Priority string `json:"priority,omitempty"`
  48. Admin string `json:"admin,omitempty"`
  49. Lastreply string `json:"lastreply,omitempty"`
  50. Flag int `json:"flag,omitempty"`
  51. Service string `json:"service,omitempty"`
  52. }
  53. // API GetTicket
  54. // https://developers.whmcs.com/api-reference/getticket/
  55. type GetTicketNote struct {
  56. Noteid int `json:"noteid"`
  57. Date string `json:"date,omitempty"`
  58. Message string `json:"message,omitempty"`
  59. Admin string `json:"admin,omitempty"`
  60. }
  61. type GetTicketReply struct {
  62. Replyid json.Number `json:"replyid"`
  63. Userid int `json:"userid"`
  64. Contactid int `json:"contactid,omitempty"`
  65. Name string `json:"name,omitempty"`
  66. Email string `json:"email,omitempty"`
  67. Requestor_name string `json:"requestor_name,omitempty"`
  68. Requestor_email string `json:"requestor_email,omitempty"`
  69. Requestor_type string `json:"requestor_type,omitempty"`
  70. Date string `json:"date,omitempty"`
  71. Message string `json:"message,omitempty"`
  72. Admin string `json:"admin,omitempty"`
  73. Rating json.Number `json:"rating,omitempty"`
  74. }
  75. type GetTicketResponse struct {
  76. APIResponse
  77. Ticketid int `json:"ticketid"`
  78. Tid string `json:"tid,omitempty"`
  79. C string `json:"c,omitempty"`
  80. Deptid int `json:"deptid,omitempty"`
  81. Deptname string `json:"deptname,omitempty"`
  82. Userid int `json:"userid,omitempty"`
  83. Contactid int `json:"contactid,omitempty"`
  84. Name string `json:"name,omitempty"`
  85. Email string `json:"email,omitempty"`
  86. Requestor_name string `json:"requestor_name,omitempty"`
  87. Requestor_type string `json:"requestor_type,omitempty"`
  88. Requestor_email string `json:"requestor_email,omitempty"`
  89. Cc string `json:"cc,omitempty"`
  90. Date string `json:"date,omitempty"`
  91. Subject string `json:"subject,omitempty"`
  92. Status string `json:"status,omitempty"`
  93. Priority string `json:"priority,omitempty"`
  94. Admin string `json:"admin,omitempty"`
  95. Lastreply string `json:"lastreply,omitempty"`
  96. Flag int `json:"flag,omitempty"`
  97. Service string `json:"service,omitempty"`
  98. Replies struct {
  99. Reply []GetTicketReply `json:"reply"`
  100. } `json:"replies"`
  101. Notes []any `json:"notes,omitempty"`
  102. }