Skip to main content

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

ctx
context.Context
required
The context for the request, used for cancellation and timeouts.
in
types.WebhookList
required
Pagination parameters for listing webhooks.

Returns

Paginator[Webhook]
types.Paginator[types.Webhook]
A paginated list of webhooks.
error
error
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)
    }
}

Example: Custom Pagination

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

GET /api/v1/webhooks
Query parameters: page, perPage

Build docs developers (and LLMs) love