-
Notifications
You must be signed in to change notification settings - Fork 1
/
support_ticket_audit.go
79 lines (66 loc) · 1.72 KB
/
support_ticket_audit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package zendesk
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
)
type TicketAudit struct {
ID TicketAuditID `json:"id"`
TicketID int `json:"ticket_id"`
CreatedAt time.Time `json:"created_at"`
AuthorID int `json:"author_id"`
Events []TicketAuditEvent `json:"events"`
}
type TicketAuditEvent struct {
ID TicketAuditEventID `json:"id"`
Type string `json:"type"`
FieldName string `json:"field_name"`
PreviousValue any `json:"previous_value"`
Value any `json:"value"`
}
type TicketAuditsResponse struct {
Audits []TicketAudit `json:"audits"`
CursorPaginationResponse
}
type TicketAuditResponse struct {
Audit TicketAudit `json:"audit"`
}
// https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_audits/
type TicketAuditService struct {
client *client
}
// https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_audits/#list-audits-for-a-ticket
func (s TicketAuditService) ListForTicket(
ctx context.Context,
ticketID TicketID,
pageHandler func(response TicketAuditsResponse) error,
) error {
query := url.Values{}
query.Set("page[size]", "100")
endpoint := fmt.Sprintf("/api/v2/tickets/%d/audits?%s", ticketID, query.Encode())
for {
target := TicketAuditsResponse{}
request, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
endpoint,
http.NoBody,
)
if err != nil {
return err
}
if err := s.client.ZendeskRequest(request, &target); err != nil {
return err
}
if err := pageHandler(target); err != nil {
return err
}
if !target.Meta.HasMore {
break
}
endpoint = target.Links.Next
}
return nil
}