AuditLogs retrieves audit logs from the given page.
(ctx context.Context, req AuditLogsRequest)
| 246 | |
| 247 | // AuditLogs retrieves audit logs from the given page. |
| 248 | func (c *Client) AuditLogs(ctx context.Context, req AuditLogsRequest) (AuditLogResponse, error) { |
| 249 | res, err := c.Request(ctx, http.MethodGet, "/api/v2/audit", nil, req.Pagination.asRequestOption(), func(r *http.Request) { |
| 250 | q := r.URL.Query() |
| 251 | var params []string |
| 252 | if req.SearchQuery != "" { |
| 253 | params = append(params, req.SearchQuery) |
| 254 | } |
| 255 | q.Set("q", strings.Join(params, " ")) |
| 256 | r.URL.RawQuery = q.Encode() |
| 257 | }) |
| 258 | if err != nil { |
| 259 | return AuditLogResponse{}, err |
| 260 | } |
| 261 | defer res.Body.Close() |
| 262 | |
| 263 | if res.StatusCode != http.StatusOK { |
| 264 | return AuditLogResponse{}, ReadBodyAsError(res) |
| 265 | } |
| 266 | |
| 267 | var logRes AuditLogResponse |
| 268 | err = json.NewDecoder(res.Body).Decode(&logRes) |
| 269 | if err != nil { |
| 270 | return AuditLogResponse{}, err |
| 271 | } |
| 272 | |
| 273 | return logRes, nil |
| 274 | } |
| 275 | |
| 276 | // CreateTestAuditLog creates a fake audit log. Only owners of the organization |
| 277 | // can perform this action. It's used for testing purposes. |