> For a complete page index, fetch https://developer.close.com/llms.txt

# Create new Webhook subscription

POST https://api.close.com/api/v1/webhook/
Content-Type: application/json

The subscription will send events to the specified URL.

Reference: https://developer.close.com/api/resources/webhooks/create

## Authentication

- `Authorization` header (basic auth, required) — Use your API key as the username and leave the password empty.
- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects a CreateWebhook.

- `events` (list of WebhookSubscriptionEvent, required) — A list of events to subscribe to. Each event has an `object_type` and an `action` from values in the [event log](https://developer.close.com/api/resources/events/list-of-event-types). You can also use [Webhook Filters](https://developer.close.com/api/resources/webhooks/webhook-filters) while creating your subscription so that an event only fires to a Webhook when certain conditions are met.
- `url` (string, required) — Destination URL for the webhook subscription
- `verify_ssl` (boolean, optional, default: true) — Verify SSL certificate of destination webhook URL. Set to `false` to disable SSL certificate validation. We recommend using https to protect your data during delivery.

## Response

### 201

Successful response

## Errors

### 400 Bad Request Error

Bad request

- `any`

### 401 Unauthorized Error

Unauthorized

- `any`

### 404 Not Found Error

Not found

- `any`

## Types

### WebhookSubscriptionEvent

- `action` (string, required)
- `object_type` (string, required)
- `extra_filter` (map from string to any, optional, nullable)

## Examples

### Basic webhook subscription

**Request**

```json
{
  "events": [
    {
      "action": "created",
      "object_type": "lead"
    },
    {
      "action": "updated",
      "object_type": "lead"
    },
    {
      "action": "created",
      "object_type": "activity.call"
    },
    {
      "action": "created",
      "object_type": "activity.note"
    },
    {
      "action": "updated",
      "object_type": "activity.note"
    },
    {
      "action": "created",
      "object_type": "activity.form_submission"
    }
  ],
  "url": "https://test.example.com"
}
```

**Response**

```json
{
  "counters": {},
  "created_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "date_created": "2018-12-06T19:15:09.590432",
  "date_updated": "2018-12-06T19:15:09.590439",
  "events": [
    {
      "action": "created",
      "object_type": "lead"
    },
    {
      "action": "updated",
      "object_type": "lead"
    },
    {
      "action": "created",
      "object_type": "activity.call"
    },
    {
      "action": "created",
      "object_type": "activity.note"
    },
    {
      "action": "updated",
      "object_type": "activity.note"
    }
  ],
  "health_status": "healthy",
  "id": "whsub_6un6NQjYTaFdgtIZsTDXP6",
  "latest_error": null,
  "pause_reason": null,
  "recent_consecutive_fail_buckets_cnt": 0,
  "signature_key": "058bfb6a3d8cfdc4da7c3be5901b16ae11da982b46a25fb2cd7016e97a140a1c",
  "status": "active",
  "updated_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "url": "https://test.example.com",
  "verify_ssl": true
}
```

**SDK Code**

```python Basic webhook subscription
import requests

url = "https://api.close.com/api/v1/webhook/"

payload = {
    "events": [
        {
            "action": "created",
            "object_type": "lead"
        },
        {
            "action": "updated",
            "object_type": "lead"
        },
        {
            "action": "created",
            "object_type": "activity.call"
        },
        {
            "action": "created",
            "object_type": "activity.note"
        },
        {
            "action": "updated",
            "object_type": "activity.note"
        },
        {
            "action": "created",
            "object_type": "activity.form_submission"
        }
    ],
    "url": "https://test.example.com"
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Basic webhook subscription
const url = 'https://api.close.com/api/v1/webhook/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"events":[{"action":"created","object_type":"lead"},{"action":"updated","object_type":"lead"},{"action":"created","object_type":"activity.call"},{"action":"created","object_type":"activity.note"},{"action":"updated","object_type":"activity.note"},{"action":"created","object_type":"activity.form_submission"}],"url":"https://test.example.com"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Basic webhook subscription
package main

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

func main() {

	url := "https://api.close.com/api/v1/webhook/"

	payload := strings.NewReader("{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.call\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.form_submission\"\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}")

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

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

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

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

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

}
```

```ruby Basic webhook subscription
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/webhook/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.call\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.form_submission\"\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}"

response = http.request(request)
puts response.read_body
```

```java Basic webhook subscription
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/webhook/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.call\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.form_submission\"\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}")
  .asString();
```

```php Basic webhook subscription
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/webhook/', [
  'body' => '{
  "events": [
    {
      "action": "created",
      "object_type": "lead"
    },
    {
      "action": "updated",
      "object_type": "lead"
    },
    {
      "action": "created",
      "object_type": "activity.call"
    },
    {
      "action": "created",
      "object_type": "activity.note"
    },
    {
      "action": "updated",
      "object_type": "activity.note"
    },
    {
      "action": "created",
      "object_type": "activity.form_submission"
    }
  ],
  "url": "https://test.example.com"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Basic webhook subscription
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/webhook/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"lead\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.call\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"updated\",\n      \"object_type\": \"activity.note\"\n    },\n    {\n      \"action\": \"created\",\n      \"object_type\": \"activity.form_submission\"\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Webhook subscription with event filter

**Request**

```json
{
  "events": [
    {
      "action": "created",
      "object_type": "lead",
      "extra_filter": {
        "field": "user_id",
        "filter": {
          "type": "equals",
          "value": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA"
        },
        "type": "field_accessor"
      }
    }
  ],
  "url": "https://test.example.com"
}
```

**Response**

```json
{
  "counters": {},
  "created_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "date_created": "2018-12-06T19:15:09.590432",
  "date_updated": "2018-12-06T19:15:09.590439",
  "events": [
    {
      "action": "created",
      "extra_filter": {
        "field": "user_id",
        "filter": {
          "type": "equals",
          "value": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA"
        },
        "type": "field_accessor"
      },
      "object_type": "lead"
    }
  ],
  "health_status": "healthy",
  "id": "whsub_6un6NQjYTaFdgtIZsTDXP6",
  "latest_error": null,
  "pause_reason": null,
  "recent_consecutive_fail_buckets_cnt": 0,
  "signature_key": "058bfb6a3d8cfdc4da7c3be5901b16ae11da982b46a25fb2cd7016e97a140a1c",
  "status": "active",
  "updated_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "url": "https://test.example.com",
  "verify_ssl": true
}
```

**SDK Code**

```python Webhook subscription with event filter
import requests

url = "https://api.close.com/api/v1/webhook/"

payload = {
    "events": [
        {
            "action": "created",
            "object_type": "lead",
            "extra_filter": {
                "field": "user_id",
                "filter": {
                    "type": "equals",
                    "value": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA"
                },
                "type": "field_accessor"
            }
        }
    ],
    "url": "https://test.example.com"
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Webhook subscription with event filter
const url = 'https://api.close.com/api/v1/webhook/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"events":[{"action":"created","object_type":"lead","extra_filter":{"field":"user_id","filter":{"type":"equals","value":"user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA"},"type":"field_accessor"}}],"url":"https://test.example.com"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Webhook subscription with event filter
package main

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

func main() {

	url := "https://api.close.com/api/v1/webhook/"

	payload := strings.NewReader("{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\",\n      \"extra_filter\": {\n        \"field\": \"user_id\",\n        \"filter\": {\n          \"type\": \"equals\",\n          \"value\": \"user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA\"\n        },\n        \"type\": \"field_accessor\"\n      }\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}")

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

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

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

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

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

}
```

```ruby Webhook subscription with event filter
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/webhook/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\",\n      \"extra_filter\": {\n        \"field\": \"user_id\",\n        \"filter\": {\n          \"type\": \"equals\",\n          \"value\": \"user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA\"\n        },\n        \"type\": \"field_accessor\"\n      }\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}"

response = http.request(request)
puts response.read_body
```

```java Webhook subscription with event filter
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/webhook/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\",\n      \"extra_filter\": {\n        \"field\": \"user_id\",\n        \"filter\": {\n          \"type\": \"equals\",\n          \"value\": \"user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA\"\n        },\n        \"type\": \"field_accessor\"\n      }\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}")
  .asString();
```

```php Webhook subscription with event filter
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/webhook/', [
  'body' => '{
  "events": [
    {
      "action": "created",
      "object_type": "lead",
      "extra_filter": {
        "field": "user_id",
        "filter": {
          "type": "equals",
          "value": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA"
        },
        "type": "field_accessor"
      }
    }
  ],
  "url": "https://test.example.com"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Webhook subscription with event filter
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/webhook/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"events\": [\n    {\n      \"action\": \"created\",\n      \"object_type\": \"lead\",\n      \"extra_filter\": {\n        \"field\": \"user_id\",\n        \"filter\": {\n          \"type\": \"equals\",\n          \"value\": \"user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA\"\n        },\n        \"type\": \"field_accessor\"\n      }\n    }\n  ],\n  \"url\": \"https://test.example.com\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```