# Webhook Configuration Resource

The **Webhook Configuration** resource allows you to precisely control the effects of **account-scoped** webhooks. Sending a `POST` request to the Webhook Configuration endpoint is equivalent to configuring session webhooks in the [Twilio Console](https://www.twilio.com/console/conversations/configuration/webhooks).

Good applications of the configured webhooks in Conversations include:

* Implementing an archival system for all Conversations
* Feeding messages into Elasticsearch
* Implementing a profanity filter across all Conversations

**Note:** You can send pre-hooks and post-hooks to different targets.

Our [guide to Conversations Webhooks](/docs/conversations/conversations-webhooks) includes the specific pre- and post-event webhooks that fire, as well as the webhook payloads.

## Webhook Properties

```json
{"type":"object","refName":"conversations.v1.configuration.configuration_webhook","modelName":"conversations_v1_configuration_configuration_webhook","properties":{"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","nullable":true,"description":"The unique ID of the [Account](/docs/iam/api/account) responsible for this conversation."},"method":{"type":"string","enum":["GET","POST"],"description":"The HTTP method to be used when sending a webhook request.","refName":"configuration_webhook_enum_method","modelName":"configuration_webhook_enum_method"},"filters":{"type":"array","nullable":true,"description":"The list of webhook event triggers that are enabled for this Service: `onMessageAdded`, `onMessageUpdated`, `onMessageRemoved`, `onMessageAdd`, `onMessageUpdate`, `onMessageRemove`, `onConversationUpdated`, `onConversationRemoved`, `onConversationAdd`, `onConversationAdded`, `onConversationRemove`, `onConversationUpdate`, `onConversationStateUpdated`, `onParticipantAdded`, `onParticipantUpdated`, `onParticipantRemoved`, `onParticipantAdd`, `onParticipantRemove`, `onParticipantUpdate`, `onDeliveryUpdated`, `onUserAdded`, `onUserUpdate`, `onUserUpdated`","items":{"type":"string"}},"pre_webhook_url":{"type":"string","nullable":true,"description":"The absolute url the pre-event webhook request should be sent to."},"post_webhook_url":{"type":"string","nullable":true,"description":"The absolute url the post-event webhook request should be sent to."},"target":{"type":"string","enum":["webhook","flex"],"description":"The routing target of the webhook. Can be ordinary or route internally to Flex","refName":"configuration_webhook_enum_target","modelName":"configuration_webhook_enum_target"},"url":{"type":"string","format":"uri","nullable":true,"description":"An absolute API resource API resource URL for this webhook."}}}
```

## Fetch a ConfigurationWebhook resource

`GET https://conversations.twilio.com/v1/Configuration/Webhooks`

FETCH: Retrieve a Webhook Configuration Resource

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function fetchConfigurationWebhook() {
  const webhook = await client.conversations.v1.configuration
    .webhooks()
    .fetch();

  console.log(webhook.accountSid);
}

fetchConfigurationWebhook();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

webhook = client.conversations.v1.configuration.webhooks().fetch()

print(webhook.account_sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Conversations.V1.Configuration;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var webhook = await WebhookResource.FetchAsync();

        Console.WriteLine(webhook.AccountSid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.conversations.v1.configuration.Webhook;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Webhook webhook = Webhook.fetcher().fetch();

        System.out.println(webhook.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	resp, err := client.ConversationsV1.FetchConfigurationWebhook()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$webhook = $twilio->conversations->v1->configuration->webhooks()->fetch();

print $webhook->accountSid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

webhook = @client
          .conversations
          .v1
          .configuration
          .webhooks
          .fetch

puts webhook.account_sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:conversations:v1:configuration:webhooks:fetch
```

```bash
curl -X GET "https://conversations.twilio.com/v1/Configuration/Webhooks" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "pre_webhook_url": "https://example.com/pre",
  "post_webhook_url": "https://example.com/post",
  "method": "GET",
  "filters": [
    "onMessageSend",
    "onConversationUpdated"
  ],
  "target": "webhook",
  "url": "https://conversations.twilio.com/v1/Configuration/Webhooks"
}
```

## Update a ConfigurationWebhook resource

`POST https://conversations.twilio.com/v1/Configuration/Webhooks`

### Request body parameters

```json
{"schema":{"type":"object","title":"UpdateConfigurationWebhookRequest","properties":{"Method":{"type":"string","description":"The HTTP method to be used when sending a webhook request."},"Filters":{"type":"array","description":"The list of webhook event triggers that are enabled for this Service: `onMessageAdded`, `onMessageUpdated`, `onMessageRemoved`, `onMessageAdd`, `onMessageUpdate`, `onMessageRemove`, `onConversationUpdated`, `onConversationRemoved`, `onConversationAdd`, `onConversationAdded`, `onConversationRemove`, `onConversationUpdate`, `onConversationStateUpdated`, `onParticipantAdded`, `onParticipantUpdated`, `onParticipantRemoved`, `onParticipantAdd`, `onParticipantRemove`, `onParticipantUpdate`, `onDeliveryUpdated`, `onUserAdded`, `onUserUpdate`, `onUserUpdated`","items":{"type":"string"}},"PreWebhookUrl":{"type":"string","description":"The absolute url the pre-event webhook request should be sent to."},"PostWebhookUrl":{"type":"string","description":"The absolute url the post-event webhook request should be sent to."},"Target":{"type":"string","enum":["webhook","flex"],"description":"The routing target of the webhook. Can be ordinary or route internally to Flex","refName":"configuration_webhook_enum_target","modelName":"configuration_webhook_enum_target"}}},"examples":{"update":{"value":{"lang":"json","value":"{\n  \"PreWebhookUrl\": \"https://example.com/pre\",\n  \"PostWebhookUrl\": \"https://example.com/post\",\n  \"Method\": \"GET\",\n  \"Filters\": [\n    \"onConversationUpdated\"\n  ],\n  \"Target\": \"webhook\"\n}","meta":"","code":"{\n  \"PreWebhookUrl\": \"https://example.com/pre\",\n  \"PostWebhookUrl\": \"https://example.com/post\",\n  \"Method\": \"GET\",\n  \"Filters\": [\n    \"onConversationUpdated\"\n  ],\n  \"Target\": \"webhook\"\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"PreWebhookUrl\"","#7EE787"],[":","#C9D1D9"]," ",["\"https://example.com/pre\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"PostWebhookUrl\"","#7EE787"],[":","#C9D1D9"]," ",["\"https://example.com/post\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Method\"","#7EE787"],[":","#C9D1D9"]," ",["\"GET\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Filters\"","#7EE787"],[": [","#C9D1D9"],"\n    ",["\"onConversationUpdated\"","#A5D6FF"],"\n  ",["],","#C9D1D9"],"\n  ",["\"Target\"","#7EE787"],[":","#C9D1D9"]," ",["\"webhook\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

UPDATE: Enable all Webhooks with filters

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updateConfigurationWebhook() {
  const webhook = await client.conversations.v1.configuration
    .webhooks()
    .update({
      filters: ["onConversationUpdated", "onMessageRemoved"],
      method: "POST",
      postWebhookUrl: "https://example.com/archive-every-action",
      preWebhookUrl: "https://example.com/filtering-and-permissions",
    });

  console.log(webhook.accountSid);
}

updateConfigurationWebhook();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

configuration_webhook = client.conversations.v1.configuration.webhooks().update(
    post_webhook_url="https://example.com/archive-every-action",
    pre_webhook_url="https://example.com/filtering-and-permissions",
    method="POST",
    filters=["onConversationUpdated", "onMessageRemoved"],
)

print(configuration_webhook.account_sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Conversations.V1.Configuration;
using System.Threading.Tasks;
using System.Collections.Generic;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var webhook = await WebhookResource.UpdateAsync(
            postWebhookUrl: "https://example.com/archive-every-action",
            preWebhookUrl: "https://example.com/filtering-and-permissions",
            method: "POST",
            filters: new List<string> { "onConversationUpdated", "onMessageRemoved" });

        Console.WriteLine(webhook.AccountSid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.util.Arrays;
import com.twilio.Twilio;
import com.twilio.rest.conversations.v1.configuration.Webhook;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Webhook webhook = Webhook.updater()
                              .setPostWebhookUrl("https://example.com/archive-every-action")
                              .setPreWebhookUrl("https://example.com/filtering-and-permissions")
                              .setMethod("POST")
                              .setFilters(Arrays.asList("onConversationUpdated", "onMessageRemoved"))
                              .update();

        System.out.println(webhook.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	conversations "github.com/twilio/twilio-go/rest/conversations/v1"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &conversations.UpdateConfigurationWebhookParams{}
	params.SetPostWebhookUrl("https://example.com/archive-every-action")
	params.SetPreWebhookUrl("https://example.com/filtering-and-permissions")
	params.SetMethod("POST")
	params.SetFilters([]string{
		"onConversationUpdated",
		"onMessageRemoved",
	})

	resp, err := client.ConversationsV1.UpdateConfigurationWebhook(params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$configuration_webhook = $twilio->conversations->v1->configuration
    ->webhooks()
    ->update([
        "postWebhookUrl" => "https://example.com/archive-every-action",
        "preWebhookUrl" => "https://example.com/filtering-and-permissions",
        "method" => "POST",
        "filters" => ["onConversationUpdated", "onMessageRemoved"],
    ]);

print $configuration_webhook->accountSid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

webhook = @client
          .conversations
          .v1
          .configuration
          .webhooks
          .update(
            post_webhook_url: 'https://example.com/archive-every-action',
            pre_webhook_url: 'https://example.com/filtering-and-permissions',
            method: 'POST',
            filters: [
              'onConversationUpdated',
              'onMessageRemoved'
            ]
          )

puts webhook.account_sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:conversations:v1:configuration:webhooks:update \
   --post-webhook-url https://example.com/archive-every-action \
   --pre-webhook-url https://example.com/filtering-and-permissions \
   --method POST \
   --filters onConversationUpdated onMessageRemoved
```

```bash
curl -X POST "https://conversations.twilio.com/v1/Configuration/Webhooks" \
--data-urlencode "PostWebhookUrl=https://example.com/archive-every-action" \
--data-urlencode "PreWebhookUrl=https://example.com/filtering-and-permissions" \
--data-urlencode "Method=POST" \
--data-urlencode "Filters=onConversationUpdated" \
--data-urlencode "Filters=onMessageRemoved" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "pre_webhook_url": "https://example.com/filtering-and-permissions",
  "post_webhook_url": "https://example.com/archive-every-action",
  "method": "POST",
  "filters": [
    "onConversationUpdated",
    "onMessageRemoved"
  ],
  "target": "webhook",
  "url": "https://conversations.twilio.com/v1/Configuration/Webhooks"
}
```
