Method Signature
func (c *Client) ListWebhooks(ctx context.Context, in types.WebhookList) (types.Paginator[types.Webhook], error)
Retrieves a paginated list of all configured webhooks.
Parameters
The context for the request, used for cancellation and timeouts.
in
types.WebhookList
required
Pagination parameters for listing webhooks.
The page number (1-based). Defaults to 1 if not provided.
Number of items per page. Defaults to 20 if not provided.
Returns
Paginator[Webhook]
types.Paginator[types.Webhook]
A paginated list of webhooks.
Array of webhook objects.
The unique identifier of the webhook.
The webhook type (e.g., slack).
The descriptive name of the webhook.
The webhook endpoint URL.
The timestamp when the webhook was created.
Information about the current page and pagination.Show PaginatorInfo Fields
Total number of webhooks available.
Number of items shown per page.
Current page number (1-based).
Index of first item on page (1-based), nil if no items.
Index of last item on page (1-based), nil if no items.
An error if the operation failed, nil otherwise.
Example
package main
import (
"context"
"fmt"
"log"
"github.com/garnet-org/api/client"
"github.com/garnet-org/api/types"
)
func main() {
// Initialize the client
c := client.New("your-api-token")
// List all webhooks with default pagination
params := types.WebhookList{}
result, err := c.ListWebhooks(context.Background(), params)
if err != nil {
log.Fatalf("Failed to list webhooks: %v", err)
}
fmt.Printf("Total webhooks: %d\n", result.PaginatorInfo.Total)
fmt.Printf("Current page: %d of %d\n",
result.PaginatorInfo.CurrentPage,
result.PaginatorInfo.LastPage)
for _, webhook := range result.Data {
fmt.Printf("\nWebhook ID: %s\n", webhook.ID)
fmt.Printf("Name: %s\n", webhook.Name)
fmt.Printf("Kind: %s\n", webhook.Kind)
fmt.Printf("URL: %s\n", webhook.URL)
fmt.Printf("Created: %v\n", webhook.CreatedAt)
}
}
func listAllWebhooks(c *client.Client) {
page := 1
perPage := 50
params := types.WebhookList{
PageArgs: types.PageArgs{
Page: &page,
PerPage: &perPage,
},
}
result, err := c.ListWebhooks(context.Background(), params)
if err != nil {
log.Fatalf("Failed to list webhooks: %v", err)
}
fmt.Printf("Retrieved %d webhooks on page %d\n",
len(result.Data), result.PaginatorInfo.CurrentPage)
// Process all pages
for page <= result.PaginatorInfo.LastPage {
for _, webhook := range result.Data {
fmt.Printf("Webhook: %s - %s\n", webhook.Name, webhook.URL)
}
// Move to next page
if page < result.PaginatorInfo.LastPage {
page++
params.Page = &page
result, err = c.ListWebhooks(context.Background(), params)
if err != nil {
log.Fatalf("Failed to fetch page %d: %v", page, err)
}
} else {
break
}
}
}
Example: Filter by Kind
func getSlackWebhooks(c *client.Client) ([]types.Webhook, error) {
params := types.WebhookList{}
result, err := c.ListWebhooks(context.Background(), params)
if err != nil {
return nil, err
}
var slackWebhooks []types.Webhook
for _, webhook := range result.Data {
if webhook.Kind == types.WebhookKindSlack {
slackWebhooks = append(slackWebhooks, webhook)
}
}
return slackWebhooks, nil
}
API Endpoint
Query parameters: page, perPage