> 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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Close API
  version: 1.0.0
paths:
  /webhook/:
    post:
      operationId: create
      summary: Create new Webhook subscription
      description: The subscription will send events to the specified URL.
      tags:
        - subpackage_webhooks
      parameters:
        - name: Authorization
          in: header
          description: Use your API key as the username and leave the password empty.
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/webhooks_create_Response_201'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                description: Any type
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                description: Any type
        '404':
          description: Not found
          content:
            application/json:
              schema:
                description: Any type
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWebhook'
servers:
  - url: https://api.close.com/api/v1
components:
  schemas:
    WebhookSubscriptionEvent:
      type: object
      properties:
        action:
          type: string
        extra_filter:
          type:
            - object
            - 'null'
          additionalProperties:
            description: Any type
        object_type:
          type: string
      required:
        - action
        - object_type
      title: WebhookSubscriptionEvent
    CreateWebhook:
      type: object
      properties:
        events:
          type: array
          items:
            $ref: '#/components/schemas/WebhookSubscriptionEvent'
          description: >-
            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:
          type: string
          description: Destination URL for the webhook subscription
        verify_ssl:
          type: boolean
          default: true
          description: >-
            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.
      required:
        - events
        - url
      title: CreateWebhook
    webhooks_create_Response_201:
      type: object
      properties: {}
      description: Empty response body
      title: webhooks_create_Response_201
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: basic
      description: Use your API key as the username and leave the password empty.
    OAuth2:
      type: http
      scheme: bearer

```

## SDK Code Examples

```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);
```

```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);
```