4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+ "strings"
7
8
"time"
8
9
)
9
10
@@ -24,11 +25,20 @@ type (
24
25
// Restriction Restriction
25
26
}
26
27
28
+ ViewCount struct {
29
+ ViewID int64 `json:"view_id"`
30
+ URL string `json:"url"`
31
+ Value int64 `json:"value"`
32
+ Pretty string `json:"pretty"`
33
+ Fresh bool `json:"fresh"`
34
+ }
35
+
27
36
// ViewAPI encapsulates methods on view
28
37
ViewAPI interface {
29
38
GetView (context.Context , int64 ) (View , error )
30
39
GetViews (context.Context ) ([]View , Page , error )
31
40
GetTicketsFromView (context.Context , int64 , * TicketListOptions ) ([]Ticket , Page , error )
41
+ GetCountTicketsInViews (ctx context.Context , ids []string ) ([]ViewCount , error )
32
42
GetTicketsFromViewIterator (ctx context.Context , opts * PaginationOptions ) * Iterator [Ticket ]
33
43
GetTicketsFromViewOBP (ctx context.Context , opts * OBPOptions ) ([]Ticket , Page , error )
34
44
GetTicketsFromViewCBP (ctx context.Context , opts * CBPOptions ) ([]Ticket , CursorPaginationMeta , error )
@@ -110,3 +120,22 @@ func (z *Client) GetTicketsFromView(ctx context.Context, viewID int64, opts *Tic
110
120
111
121
return result .Tickets , result .Page , nil
112
122
}
123
+
124
+ // GetCountTicketsInViews count tickets in views using views ids
125
+ // ref https://developer.zendesk.com/api-reference/ticketing/business-rules/views/#count-tickets-in-views
126
+ func (z * Client ) GetCountTicketsInViews (ctx context.Context , ids []string ) ([]ViewCount , error ) {
127
+ var result struct {
128
+ ViewCounts []ViewCount `json:"view_counts"`
129
+ }
130
+ idsURLParameter := strings .Join (ids , "," )
131
+ body , err := z .get (ctx , fmt .Sprintf ("/views/count_many?ids=%s" , idsURLParameter ))
132
+
133
+ if err != nil {
134
+ return []ViewCount {}, err
135
+ }
136
+
137
+ if err := json .Unmarshal (body , & result ); err != nil {
138
+ return []ViewCount {}, err
139
+ }
140
+ return result .ViewCounts , nil
141
+ }
0 commit comments