# Create

To create a new webhook you need to execute a **POST** request against the **/webhooks** endpoint.

* **endpoint** **->** the URL where the webhook will send the **POST** request to.
* **events ->** an array of events for which the webhook will trigger. Read about the currently available events [here](https://docs.digitalsamba.com/reference/rest-api/webhooks). In the future support for more events will be added -> e.g. to able to receive a webhook when a recording is started or has been processed.
* **authorization\_header ->** The authorization header is a secret which only your backend and DigitalSamba know about. It is an optional field, but its highly recommended to use it, so you can protect your endpoint from unauthorized calls. The webhook will send the secret as a standard **Authorization Bearer** http header.
* **name** -> optional text description of your webhook

{% hint style="info" %}
For quick testing you may want to use as endpoint <https://webhook.site/> which is a free public service. It allows you to inspect the payload structure of the received webhook requests.
{% endhint %}

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request POST \
  --header "Content-Type: application/json" \
  --url https://api.digitalsamba.com/api/v1/webhooks \
  --user YOUR_TEAM_ID:YOUR_DEVELOPER_KEY \
  --data '{
     "endpoint": "https://YOUR_BACKEND_ENDPOINT_URL", 
     "events": ["participant_joined", "participant_left"], 
     "name": "Testing my first webhook",
     "authorization_header": "Asf#k$%lfCaPe93$a"
  }'
```

{% endtab %}

{% tab title="Java" %}

```java
import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Base64;
import java.util.Map;

String TEAM_ID = "YOUR_TEAM_ID";
String DEVELOPER_KEY = "YOUR_DEVELOPER_KEY";
String authorizationHeader = "Bearer " + Base64.getEncoder().encodeToString((TEAM_ID + ":" + DEVELOPER_KEY).getBytes());

String backendWebhookUrl = "https://YOUR_BACKEND_ENDPOINT_URL";
String webhookSecret = "Asf#k$%lfCaPe93$a";

Map<String, Object> data = Map.of(
  "endpoint", backendWebhookUrl,
  "events", new String[] {"participant_joined", "participant_left"},
  "name", "Testing my first webhook",
  "authorization_header", webhookSecret
);
String jsonData = new ObjectMapper().writeValueAsString(data);

HttpRequest request = HttpRequest.newBuilder()
  .POST(HttpRequest.BodyPublishers.ofString(jsonData))
  .uri(new URI("https://api.digitalsamba.com/api/v1/webhooks"))
  .header("Authorization", authorizationHeader)
  .header("Content-Type", "application/json")
  .build();

HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

System.out.println("Status code: " + response.statusCode());
System.out.println("Body: " + response.body());
```

{% endtab %}
{% endtabs %}

#### Response (200 OK)

```json
{
    "id": "7adb1f07-db15-4cdc-8bf0-2be746fcec2a",
    "endpoint": "https://YOUR_BACKEND_ENDPOINT_URL",
    "authorization_header": "Asf#k$%lfCaPe93$a",
    "name": "Testing my first webhook",
    "events": [
        "participant_joined",
        "participant_left"
    ],
    "created_at": "2023-02-06T09:43:48Z",
    "updated_at": "2023-02-06T09:43:48Z"
}
```

{% hint style="info" %}
Read about the [payload structure](https://docs.digitalsamba.com/reference/rest-api/webhooks/payload-structure) which you will receive at your configured endpoint.
{% endhint %}
