> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://uploadcare.com/docs/llms.txt.

# Create webhook

POST https://api.uploadcare.com/webhooks/
Content-Type: application/x-www-form-urlencoded

Create and subscribe to a webhook. You can use webhooks to receive notifications about your uploads. For instance, once a file gets uploaded to your project, we can notify you by sending a message to a target URL.

Reference: https://uploadcare.com/docs/api/rest/webhook/create

## Authentication

- `Authorization` header (required) — Every request made to `https://api.uploadcare.com/` MUST be signed. HTTPS SHOULD be used with any authorization scheme. Requests MUST contain the `Authorization` header defining `auth-scheme` and `auth-param`: `Authorization: auth-scheme auth-param`. Every request MUST contain the `Accept` header identifying the REST API version: `Accept: application/vnd.uploadcare-v0.7+json`. There are two available authorization schemes: * For production: `Uploadcare`, a scheme where a `signature`, not your Secret API Key MUST be specified. Signatures SHOULD be generated on backend. * For quick tests: `Uploadcare.Simple`, a simple scheme where your [Secret API Key](https://app.uploadcare.com/projects/-/api-keys/) MUST be specified in every request's `auth-param`.

## Request

### Headers

- `Accept` (string, required) — Version header.

### Body (application/x-www-form-urlencoded)

This endpoint expects an object.

- `target_url` (string, required) — A URL that is triggered by an event, for example, a file upload. A target URL MUST be unique for each `project` — `event type` combination.
- `event` (enum, required) — An event you subscribe to.
  - Allowed values: `file.uploaded`, `file.infected`, `file.stored`, `file.deleted`, `file.info_updated`
- `is_active` (boolean, optional, default: true) — Marks a subscription as either active or not, defaults to `true`, otherwise `false`.
- `signing_secret` (string, optional) — Optional [HMAC/SHA-256](https://en.wikipedia.org/wiki/HMAC) secret that, if set, will be used to calculate signatures for the webhook payloads sent to the `target_url`. Calculated signature will be sent to the `target_url` as a value of the `X-Uc-Signature` HTTP header. The header will have the following format: `X-Uc-Signature: v1=<HMAC-SHA256-HEX-DIGEST>`. See [Secure Webhooks](https://uploadcare.com/docs/webhooks/#signed-webhooks) for details.
- `version` (enum, optional, default: 0.7) — Webhook payload's version.
  - Allowed values: `0.7`

## Response

### 201

Webhook successfully created.

- `id` (integer, optional) — Webhook's ID.
- `project` (integer, optional) — Project ID the webhook belongs to.
- `created` (datetime, optional) — date-time when a webhook was created.
- `updated` (datetime, optional) — date-time when a webhook was updated.
- `event` (enum, optional) — An event you subscribe to.
  - Allowed values: `file.uploaded`, `file.infected`, `file.stored`, `file.deleted`, `file.info_updated`
- `target_url` (string, optional) — A URL that is triggered by an event, for example, a file upload. A target URL MUST be unique for each `project` — `event type` combination.
- `is_active` (boolean, optional, default: true) — Marks a subscription as either active or not, defaults to `true`, otherwise `false`.
- `version` (enum, optional) — Webhook payload's version.
  - Allowed values: ``, `0.5`, `0.6`, `0.7`
- `signing_secret` (string, optional) — Optional [HMAC/SHA-256](https://en.wikipedia.org/wiki/HMAC) secret that, if set, will be used to calculate signatures for the webhook payloads sent to the `target_url`. Calculated signature will be sent to the `target_url` as a value of the `X-Uc-Signature` HTTP header. The header will have the following format: `X-Uc-Signature: v1=<HMAC-SHA256-HEX-DIGEST>`. See [Secure Webhooks](https://uploadcare.com/docs/webhooks/#signed-webhooks) for details.

## Errors

### 400 Bad Request Error

Simple HTTP Auth or webhook permission or endpoint errors.

- `WebhookCreateRequestBadRequestError`

### 401 Unauthorized Error

Authorization errors.

- `detail` (enum, optional)
  - Allowed values: `Incorrect authentication credentials.`, `Public key {public_key} not found.`, `Secret key not found.`, `Invalid signature. Please check your Secret key.`

### 406 Not Acceptable Error

Invalid version header `Accept` for this endpoint.

- `detail` (string, optional, default: Incorrect Accept header provided. Make sure to specify API version. Refer to REST API docs for details.)

### 429 Too Many Requests Error

Request was throttled.

- `detail` (string, optional)

## Types

### simpleAuthHTTPForbidden

- `detail` (string, optional, default: Simple authentication over HTTP is forbidden. Please, use HTTPS or signed requests instead.)

### cantUseWebhooksError

- `detail` (string, optional, default: You can't use webhooks)

### webhookTargetUrlError

- `detail` (string, optional, default: `target_url` is missing.) — `target_url` is missing.

## Examples

**Request**

```json
{
  "target_url": "http://example.com/hooks/receiver",
  "event": "file.uploaded"
}
```

**Response**

```json
{
  "id": 1,
  "project": 13,
  "created": "2016-04-27T11:49:54.948615Z",
  "updated": "2016-04-27T12:04:57.819933Z",
  "event": "file.infected",
  "target_url": "http://example.com/hooks/receiver",
  "is_active": true,
  "version": "0.7",
  "signing_secret": "7kMVZivndx0ErgvhRKAr"
}
```

**SDK Code**

```javascript JS
import {
  createWebhook,
  UploadcareSimpleAuthSchema,
} from '@uploadcare/rest-client';

const uploadcareSimpleAuthSchema = new UploadcareSimpleAuthSchema({
  publicKey: 'YOUR_PUBLIC_KEY',
  secretKey: 'YOUR_SECRET_KEY',
});

const result = await createWebhook(
  {
    targetUrl: 'https://yourwebhook.com',
    event: 'file.uploaded',
    isActive: true,
  },
  { authSchema: uploadcareSimpleAuthSchema }
)

```

```php PHP
<?php
$configuration = Uploadcare\Configuration::create((string) $_ENV['UPLOADCARE_PUBLIC_KEY'], (string) $_ENV['UPLOADCARE_SECRET_KEY']);

$api = (new Uploadcare\Api($configuration))->webhook();
$result = $api->createWebhook('https://yourwebhook.com', true, 'sign-secret', 'file.uploaded');
echo \sprintf('Webhook %s created', $result->getId());

```

```python Python
from pyuploadcare import Uploadcare, Webhook
uploadcare = Uploadcare(public_key='YOUR_PUBLIC_KEY', secret_key='YOUR_SECRET_KEY')

webhook = uploadcare.webhooks_api.create(
    {
        "event": "file.uploaded",
        "target_url": "https://yourwebhook.com",
        "is_active": True,
    }
)
print(webhook)

```

```ruby Ruby
require 'uploadcare'
Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'

options = {
  target_url: 'https://yourwebhook.com',
  event: 'file.uploaded',
  is_active: true
}
Uploadcare::Webhook.create(**options)

```

```swift Swift
import Uploadcare

let uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")

let url = URL(string: "https://yourwebhook.com")!
let webhook = try await uploadcare.createWebhook(targetUrl: url,  event: .fileUploaded, isActive: true, signingSecret: "sign-secret")
print(webhook)

```

```kotlin Kotlin
import com.uploadcare.android.library.api.UploadcareClient

val uploadcare = UploadcareClient(publicKey = "YOUR_PUBLIC_KEY", secretKey = "YOUR_SECRET_KEY")

val url = URI("https://yourwebhook.com")
val webhook = uploadcare.createWebhook(
    targetUrl = url,
    event = EventType.UPLOADED,
    isActive = true,
    signingSecret = "sign-secret"
)
Log.d("TAG", webhook.toString())

```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.uploadcare.com/webhooks/"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Accept", "application/vnd.uploadcare-v0.7+json")
	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.uploadcare.com/webhooks/")
  .header("Accept", "application/vnd.uploadcare-v0.7+json")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .asString();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.uploadcare.com/webhooks/");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/vnd.uploadcare-v0.7+json");
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
```