# `ApifyClient.API.Webhooks`
[🔗](https://github.com/social-growth-studio/apify-client-ex/blob/v1.0.0/lib/apify_client/api/webhooks.ex#L1)

Provides API endpoints related to api/webhooks

# `create`

```elixir
@spec create(
  body :: map() | ApifyClient.Schemas.CreateWebhookRequest.t(),
  opts :: keyword()
) ::
  {:ok, ApifyClient.Schemas.WebhookResource.t()}
  | {:error, ApifyClient.Error.t()}
```

Create webhook

Creates a new webhook with settings provided by the webhook object passed as
JSON in the payload.
The response is the created webhook object.

To avoid duplicating a webhook, use the `idempotencyKey` parameter in the
request body.
Multiple calls to create a webhook with the same `idempotencyKey` will only
create the webhook with the first call and return the existing webhook on
subsequent calls.
Idempotency keys must be unique, so use a UUID or another random string with
enough entropy.

To assign the new webhook to an Actor or task, the request body must contain
`requestUrl`, `eventTypes`, and `condition` properties.

* `requestUrl` is the webhook's target URL, to which data is sent as a POST
request with a JSON payload.
* `eventTypes` is a list of events that will trigger the webhook, e.g. when
the Actor run succeeds.
* `condition` should be an object containing the ID of the Actor or task to
which the webhook will be assigned.
* `payloadTemplate` is a JSON-like string, whose syntax is extended with the
use of variables.
* `headersTemplate` is a JSON-like string, whose syntax is extended with the
use of variables. Following values will be re-written to defaults: "host",
"Content-Type", "X-Apify-Webhook", "X-Apify-Webhook-Dispatch-Id",
"X-Apify-Request-Origin"
* `description` is an optional string.
* `shouldInterpolateStrings` is a boolean indicating whether to interpolate
variables contained inside strings in the `payloadTemplate`

```
    "isAdHoc" : false,
    "requestUrl" : "https://example.com",
    "eventTypes" : [
        "ACTOR.RUN.SUCCEEDED",
        "ACTOR.RUN.ABORTED"
    ],
    "condition" : {
        "actorId": "5sTMwDQywwsLzKRRh",
        "actorTaskId" : "W9bs9JE9v7wprjAnJ"
    },
    "payloadTemplate": "",
    "headersTemplate": "",
    "description": "my awesome webhook",
    "shouldInterpolateStrings": false,
```

**Important**: The request must specify the `Content-Type: application/json`
HTTP header.

## Request Body

**Content Types**: `application/json`

# `delete`

```elixir
@spec delete(webhook_id :: String.t(), opts :: keyword()) ::
  :ok | {:error, ApifyClient.Error.t()}
```

Delete webhook

Deletes a webhook.

# `get`

```elixir
@spec get(webhook_id :: String.t(), opts :: keyword()) ::
  {:ok, ApifyClient.Schemas.WebhookResource.t()}
  | {:error, ApifyClient.Error.t()}
```

Get webhook

Gets webhook object with all details.

# `list`

```elixir
@spec list(opts :: keyword()) ::
  {:ok, ApifyClient.Schemas.ListOfWebhooks.t()}
  | {:error, ApifyClient.Error.t()}
```

Get list of webhooks

Gets the list of webhooks that the user created.

The endpoint supports pagination using the `limit` and `offset` parameters
and it will not return more than 1000 records.
By default, the records are sorted by the `createdAt` field in ascending
order. To sort the records in descending order, use the `desc=1`
parameter.

## Options

  * `offset`: Number of items that should be skipped at the start. The default value is `0`.
    
  * `limit`: Maximum number of items to return. The default value as well as the maximum is `1000`.
    
  * `desc`: If `true` or `1` then the objects are sorted by the `createdAt` field in
    descending order. By default, they are sorted in ascending order.
    

# `test`

```elixir
@spec test(webhook_id :: String.t(), opts :: keyword()) ::
  {:ok, ApifyClient.Schemas.WebhookDispatch.t()}
  | {:error, ApifyClient.Error.t()}
```

Test webhook

Tests a webhook. Creates a webhook dispatch with a dummy payload.

# `update`

```elixir
@spec update(
  webhook_id :: String.t(),
  body :: map() | ApifyClient.Schemas.UpdateWebhookRequest.t(),
  opts :: keyword()
) ::
  {:ok, ApifyClient.Schemas.WebhookResource.t()}
  | {:error, ApifyClient.Error.t()}
```

Update webhook

Updates a webhook using values specified by a webhook object passed as JSON
in the POST payload.
If the object does not define a specific property, its value will not be
updated.

The response is the full webhook object as returned by the
[Get webhook](https://docs.apify.com/api/v2/webhook-get) endpoint.

The request needs to specify the `Content-Type: application/json` HTTP
header!

When providing your API authentication token, we recommend using the
request's `Authorization` header, rather than the URL.
For details, see [Authentication](https://docs.apify.com/api/v2#authentication).

## Request Body

**Content Types**: `application/json`

---

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