# `HuggingfaceClient.Hub.Webhooks`
[🔗](https://github.com/huggingface/huggingface_client/blob/v0.1.0/lib/huggingface_client/hub/collaboration/webhooks.ex#L1)

Manage webhooks on the HuggingFace Hub.

Webhooks allow you to receive real-time notifications when repos are updated,
pull requests are opened, comments are posted, etc.

See: https://huggingface.co/docs/hub/webhooks

## Example

    # Create a webhook watching a user's models
    {:ok, wh} = HuggingfaceClient.create_webhook(
      url: "https://my-server.example.com/webhook",
      watched: [%{type: "user", name: "my-user"}],
      domains: ["repo", "discussion"],
      secret: "my-secret",
      access_token: "hf_..."
    )

    IO.puts("Webhook ID: #{wh["id"]}")

    # List all webhooks
    {:ok, webhooks} = HuggingfaceClient.list_webhooks(access_token: "hf_...")

# `create`

```elixir
@spec create(keyword()) :: {:ok, map()} | {:error, Exception.t()}
```

Creates a new webhook.

## Options

- `:url` — HTTPS URL that will receive the webhook events (required)
- `:watched` — list of items to watch. Each is a map with `:type` (user, org, model, dataset, space)
  and `:name`. Example: `[%{type: "user", name: "my-user"}]`
- `:domains` — list of event domains to watch: `"repo"` and/or `"discussion"` (default: both)
- `:secret` — optional secret to verify payloads
- `:access_token`

## Example

    {:ok, webhook} = HuggingfaceClient.create_webhook(
      url: "https://my-server.com/hook",
      watched: [%{type: "model", name: "bert-base-uncased"}],
      domains: ["repo"],
      access_token: "hf_..."
    )

# `delete`

```elixir
@spec delete(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}
```

Deletes a webhook.

## Example

    :ok = HuggingfaceClient.delete_webhook("wh-id", access_token: "hf_...")

# `get`

```elixir
@spec get(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Gets information about a specific webhook.

## Example

    {:ok, wh} = HuggingfaceClient.get_webhook("my-webhook-id", access_token: "hf_...")

# `list`

```elixir
@spec list(keyword()) :: {:ok, [map()]} | {:error, Exception.t()}
```

Lists all webhooks belonging to the authenticated user.

## Example

    {:ok, webhooks} = HuggingfaceClient.list_webhooks(access_token: "hf_...")
    Enum.each(webhooks, fn w -> IO.puts(w["url"]) end)

# `update`

```elixir
@spec update(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Updates an existing webhook.

## Options

Same as `create/1`. Only provided fields are updated.

## Example

    {:ok, updated} = HuggingfaceClient.update_webhook("wh-id",
      url: "https://new-url.example.com/hook",
      access_token: "hf_..."
    )

---

*Consult [api-reference.md](api-reference.md) for complete listing*
